@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
package/dist/index.browser.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Errors, LLTV,
|
|
1
|
+
import { Errors, LLTV, Offer, Utils, Format } from '@morpho-dev/mempool';
|
|
2
2
|
export * from '@morpho-dev/mempool';
|
|
3
3
|
import { parseUnits, encodeAbiParameters, maxUint256, formatUnits, decodeAbiParameters, erc20Abi } from 'viem';
|
|
4
4
|
import { Base64 } from 'js-base64';
|
|
@@ -34,46 +34,95 @@ var WhitelistedCallbackAddresses = {
|
|
|
34
34
|
"0x1111111111111111111111111111111111111111",
|
|
35
35
|
"0x2222222222222222222222222222222222222222"
|
|
36
36
|
// @TODO: update once deployed and add mapping per chain if needed
|
|
37
|
-
]
|
|
37
|
+
].map((address) => address.toLowerCase())
|
|
38
38
|
};
|
|
39
39
|
function buildLiquidity(parameters) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
},
|
|
54
|
-
queues: [
|
|
55
|
-
{
|
|
56
|
-
queue: {
|
|
57
|
-
queueId: id,
|
|
58
|
-
availableLiquidityPoolId: id,
|
|
59
|
-
index,
|
|
40
|
+
switch (parameters.type) {
|
|
41
|
+
case "buy_with_empty_callback" /* BuyWithEmptyCallback */: {
|
|
42
|
+
const { user, loanToken, chainId, amount, index = 0, updatedAt = /* @__PURE__ */ new Date() } = parameters;
|
|
43
|
+
const amountStr = amount.toString();
|
|
44
|
+
const id = `${user}-${chainId.toString()}-${parameters.type}-${loanToken}`.toLowerCase();
|
|
45
|
+
const poolId = `${user}-${chainId.toString()}-${loanToken}`.toLowerCase();
|
|
46
|
+
return {
|
|
47
|
+
userPosition: {
|
|
48
|
+
id,
|
|
49
|
+
availableLiquidityQueueId: id,
|
|
50
|
+
user: user.toLowerCase(),
|
|
51
|
+
chainId,
|
|
52
|
+
amount: amountStr,
|
|
60
53
|
updatedAt
|
|
61
54
|
},
|
|
62
|
-
|
|
55
|
+
queues: [
|
|
56
|
+
{
|
|
57
|
+
queue: {
|
|
58
|
+
queueId: id,
|
|
59
|
+
availableLiquidityPoolId: poolId,
|
|
60
|
+
index,
|
|
61
|
+
callbackAmount: "0",
|
|
62
|
+
updatedAt
|
|
63
|
+
},
|
|
64
|
+
pool: {
|
|
65
|
+
id: poolId,
|
|
66
|
+
amount: amountStr,
|
|
67
|
+
updatedAt
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
case "sell_withdraw_from_wallet" /* SellWithdrawFromWallet */: {
|
|
74
|
+
const {
|
|
75
|
+
user,
|
|
76
|
+
termId,
|
|
77
|
+
chainId,
|
|
78
|
+
amount,
|
|
79
|
+
collaterals,
|
|
80
|
+
index = 0,
|
|
81
|
+
updatedAt = /* @__PURE__ */ new Date()
|
|
82
|
+
} = parameters;
|
|
83
|
+
const amountStr = amount.toString();
|
|
84
|
+
const id = `${user}-${chainId.toString()}-${parameters.type}-${termId}`.toLowerCase();
|
|
85
|
+
return {
|
|
86
|
+
userPosition: {
|
|
63
87
|
id,
|
|
88
|
+
availableLiquidityQueueId: id,
|
|
89
|
+
user: user.toLowerCase(),
|
|
90
|
+
chainId,
|
|
64
91
|
amount: amountStr,
|
|
65
92
|
updatedAt
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
93
|
+
},
|
|
94
|
+
queues: collaterals.map((collateral) => {
|
|
95
|
+
const poolId = `${user}-${chainId.toString()}-${collateral.collateralAddress}`.toLowerCase();
|
|
96
|
+
return {
|
|
97
|
+
queue: {
|
|
98
|
+
queueId: id,
|
|
99
|
+
availableLiquidityPoolId: poolId,
|
|
100
|
+
index,
|
|
101
|
+
callbackAmount: collateral.callbackAmount.toString(),
|
|
102
|
+
updatedAt
|
|
103
|
+
},
|
|
104
|
+
pool: {
|
|
105
|
+
id: poolId,
|
|
106
|
+
amount: collateral.balance.toString(),
|
|
107
|
+
updatedAt
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
})
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
default: {
|
|
114
|
+
throw new Error(`CallbackType not implemented`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
70
117
|
}
|
|
71
118
|
function getCallbackIdForOffer(offer) {
|
|
72
119
|
if (offer.buy && offer.callback.data === "0x") {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
120
|
+
return `${offer.offering}-${offer.chainId.toString()}-${"buy_with_empty_callback" /* BuyWithEmptyCallback */}-${offer.loanToken}`.toLowerCase();
|
|
121
|
+
}
|
|
122
|
+
if (!offer.buy && offer.callback.data !== "0x" && WhitelistedCallbackAddresses["sell_withdraw_from_wallet" /* SellWithdrawFromWallet */].includes(
|
|
123
|
+
offer.callback.address.toLowerCase()
|
|
124
|
+
)) {
|
|
125
|
+
return `${offer.offering}-${offer.chainId.toString()}-${"sell_withdraw_from_wallet" /* SellWithdrawFromWallet */}-${Offer.termId(offer)}`.toLowerCase();
|
|
77
126
|
}
|
|
78
127
|
return null;
|
|
79
128
|
}
|
|
@@ -269,20 +318,20 @@ async function fetch2(parameters) {
|
|
|
269
318
|
const map = await fetchBalancesAndAllowances({
|
|
270
319
|
client,
|
|
271
320
|
spender,
|
|
272
|
-
pairs: pairs.map(({ user,
|
|
321
|
+
pairs: pairs.map(({ user, loanToken }) => ({ user, token: loanToken })),
|
|
273
322
|
options
|
|
274
323
|
});
|
|
275
324
|
const out = [];
|
|
276
|
-
for (const [user,
|
|
277
|
-
for (const [
|
|
325
|
+
for (const [user, perLoanToken] of map) {
|
|
326
|
+
for (const [loanToken, { balance, allowance }] of perLoanToken) {
|
|
278
327
|
const amount = balance < allowance ? balance : allowance;
|
|
279
328
|
out.push(
|
|
280
329
|
buildLiquidity({
|
|
281
330
|
type,
|
|
282
331
|
user,
|
|
283
|
-
|
|
332
|
+
loanToken,
|
|
284
333
|
chainId,
|
|
285
|
-
amount
|
|
334
|
+
amount,
|
|
286
335
|
index: 0
|
|
287
336
|
})
|
|
288
337
|
);
|