@ember-finance/sdk 2.11.0-pre.6 → 2.11.0
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/src/abis/EmberDepositParkingLot.json +175 -43
- package/dist/src/api/v2/apis/vaults-api.d.ts +0 -42
- package/dist/src/api/v2/apis/vaults-api.js +0 -87
- package/dist/src/api/v2/models/chain.d.ts +0 -6
- package/dist/src/api/v2/models/index.d.ts +0 -3
- package/dist/src/api/v2/models/index.js +0 -3
- package/dist/src/api/v2/models/instant-withdraw-config.d.ts +2 -21
- package/dist/src/api/v2/models/poc-report-protocol.d.ts +0 -13
- package/dist/src/api/v2/models/transparency-row.d.ts +1 -1
- package/dist/src/evm-vaults/interfaces/index.d.ts +5 -0
- package/dist/src/evm-vaults/on-chain-calls/operator.d.ts +16 -0
- package/dist/src/evm-vaults/on-chain-calls/operator.js +20 -0
- package/dist/src/evm-vaults/on-chain-calls/tx-builder.d.ts +21 -0
- package/dist/src/evm-vaults/on-chain-calls/tx-builder.js +39 -0
- package/dist/src/evm-vaults/on-chain-calls/vault-admin.d.ts +16 -0
- package/dist/src/evm-vaults/on-chain-calls/vault-admin.js +20 -0
- package/dist/src/evm-vaults/on-chain-calls/vault-reader.js +3 -1
- package/package.json +1 -6
- package/dist/src/api/v2/models/coin-placement.d.ts +0 -113
- package/dist/src/api/v2/models/coin-placement.js +0 -17
- package/dist/src/api/v2/models/coin-placements-response.d.ts +0 -25
- package/dist/src/api/v2/models/coin-placements-response.js +0 -14
- package/dist/src/api/v2/models/poc-report-protocol-asset.d.ts +0 -60
- package/dist/src/api/v2/models/poc-report-protocol-asset.js +0 -18
- package/dist/src/placements/adapters/alphalend.d.ts +0 -1
- package/dist/src/placements/adapters/alphalend.js +0 -58
- package/dist/src/placements/adapters/bluefin-spot.d.ts +0 -1
- package/dist/src/placements/adapters/bluefin-spot.js +0 -78
- package/dist/src/placements/adapters/current.d.ts +0 -1
- package/dist/src/placements/adapters/current.js +0 -70
- package/dist/src/placements/adapters/evm-protocols.d.ts +0 -1
- package/dist/src/placements/adapters/evm-protocols.js +0 -8
- package/dist/src/placements/adapters/factory.d.ts +0 -15
- package/dist/src/placements/adapters/factory.js +0 -62
- package/dist/src/placements/adapters/index.d.ts +0 -14
- package/dist/src/placements/adapters/index.js +0 -25
- package/dist/src/placements/adapters/navi.d.ts +0 -1
- package/dist/src/placements/adapters/navi.js +0 -53
- package/dist/src/placements/adapters/pendle.d.ts +0 -9
- package/dist/src/placements/adapters/pendle.js +0 -108
- package/dist/src/placements/adapters/royco.d.ts +0 -2
- package/dist/src/placements/adapters/royco.js +0 -49
- package/dist/src/placements/adapters/suilend.d.ts +0 -1
- package/dist/src/placements/adapters/suilend.js +0 -57
- package/dist/src/placements/batch.d.ts +0 -70
- package/dist/src/placements/batch.js +0 -197
- package/dist/src/placements/client.d.ts +0 -17
- package/dist/src/placements/client.js +0 -194
- package/dist/src/placements/evm.d.ts +0 -29
- package/dist/src/placements/evm.js +0 -280
- package/dist/src/placements/index.d.ts +0 -8
- package/dist/src/placements/index.js +0 -8
- package/dist/src/placements/pointers.d.ts +0 -24
- package/dist/src/placements/pointers.js +0 -126
- package/dist/src/placements/registry.d.ts +0 -11
- package/dist/src/placements/registry.js +0 -19
- package/dist/src/placements/sui.d.ts +0 -47
- package/dist/src/placements/sui.js +0 -302
- package/dist/src/placements/types.d.ts +0 -147
- package/dist/src/placements/types.js +0 -1
- package/dist/src/placements/vaults.d.ts +0 -15
- package/dist/src/placements/vaults.js +0 -97
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
export class TransientError extends Error {
|
|
2
|
-
constructor(message, retryAfterMs) {
|
|
3
|
-
super(message);
|
|
4
|
-
this.name = "TransientError";
|
|
5
|
-
this.retryAfterMs = retryAfterMs;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export class ChunkTooLargeError extends Error {
|
|
9
|
-
constructor(message) {
|
|
10
|
-
super(message);
|
|
11
|
-
this.name = "ChunkTooLargeError";
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export class AbortedError extends Error {
|
|
15
|
-
constructor(message = "aborted") {
|
|
16
|
-
super(message);
|
|
17
|
-
this.name = "AbortedError";
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export function retryAfterMs(header) {
|
|
21
|
-
if (!header)
|
|
22
|
-
return undefined;
|
|
23
|
-
const seconds = Number(header);
|
|
24
|
-
if (Number.isFinite(seconds))
|
|
25
|
-
return Math.max(0, seconds * 1000);
|
|
26
|
-
const at = Date.parse(header);
|
|
27
|
-
return Number.isNaN(at) ? undefined : Math.max(0, at - Date.now());
|
|
28
|
-
}
|
|
29
|
-
export function isTransientStatus(status) {
|
|
30
|
-
return status === 429 || status >= 500;
|
|
31
|
-
}
|
|
32
|
-
export function isAbortError(error) {
|
|
33
|
-
return (error instanceof AbortedError ||
|
|
34
|
-
(error instanceof Error && error.name === "AbortError"));
|
|
35
|
-
}
|
|
36
|
-
const defaultSleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
37
|
-
const defaultSchedule = (flush) => {
|
|
38
|
-
setTimeout(flush, 0);
|
|
39
|
-
};
|
|
40
|
-
export class Batcher {
|
|
41
|
-
constructor(options) {
|
|
42
|
-
this.queue = [];
|
|
43
|
-
this.inFlight = new Map();
|
|
44
|
-
this.waiting = [];
|
|
45
|
-
this.active = 0;
|
|
46
|
-
this.scheduled = false;
|
|
47
|
-
this.send = options.send;
|
|
48
|
-
this.key = options.key;
|
|
49
|
-
this.weight = options.weight ?? (() => 1);
|
|
50
|
-
this.bytes = options.bytes ?? (() => 0);
|
|
51
|
-
this.maxWeight = options.maxWeight ?? 10;
|
|
52
|
-
this.maxBytes = options.maxBytes ?? Number.POSITIVE_INFINITY;
|
|
53
|
-
this.concurrency = options.concurrency ?? 3;
|
|
54
|
-
this.retries = options.retries ?? 3;
|
|
55
|
-
this.baseDelayMs = options.baseDelayMs ?? 300;
|
|
56
|
-
this.maxDelayMs = options.maxDelayMs ?? 10000;
|
|
57
|
-
this.sleep = options.sleep ?? defaultSleep;
|
|
58
|
-
this.schedule = options.schedule ?? defaultSchedule;
|
|
59
|
-
this.signal = options.signal;
|
|
60
|
-
}
|
|
61
|
-
enqueue(item) {
|
|
62
|
-
if (this.signal?.aborted)
|
|
63
|
-
return Promise.reject(new AbortedError());
|
|
64
|
-
const key = this.key(item);
|
|
65
|
-
const shared = this.inFlight.get(key);
|
|
66
|
-
if (shared)
|
|
67
|
-
return shared;
|
|
68
|
-
const promise = new Promise((resolve, reject) => {
|
|
69
|
-
this.queue.push({ item, resolve, reject });
|
|
70
|
-
});
|
|
71
|
-
this.inFlight.set(key, promise);
|
|
72
|
-
const forget = () => {
|
|
73
|
-
if (this.inFlight.get(key) === promise)
|
|
74
|
-
this.inFlight.delete(key);
|
|
75
|
-
};
|
|
76
|
-
promise.then(forget, forget);
|
|
77
|
-
this.scheduleFlush();
|
|
78
|
-
return promise;
|
|
79
|
-
}
|
|
80
|
-
scheduleFlush() {
|
|
81
|
-
if (this.scheduled)
|
|
82
|
-
return;
|
|
83
|
-
this.scheduled = true;
|
|
84
|
-
this.schedule(() => {
|
|
85
|
-
this.scheduled = false;
|
|
86
|
-
this.flush();
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
flush() {
|
|
90
|
-
const pending = this.queue.splice(0);
|
|
91
|
-
for (const chunk of this.chunk(pending)) {
|
|
92
|
-
void this.run(chunk, 1);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
chunk(pending) {
|
|
96
|
-
const chunks = [];
|
|
97
|
-
let current = [];
|
|
98
|
-
let weight = 0;
|
|
99
|
-
let bytes = 0;
|
|
100
|
-
for (const entry of pending) {
|
|
101
|
-
const entryWeight = this.weight(entry.item);
|
|
102
|
-
const entryBytes = this.bytes(entry.item);
|
|
103
|
-
const overflows = weight + entryWeight > this.maxWeight ||
|
|
104
|
-
bytes + entryBytes > this.maxBytes;
|
|
105
|
-
if (current.length > 0 && overflows) {
|
|
106
|
-
chunks.push(current);
|
|
107
|
-
current = [];
|
|
108
|
-
weight = 0;
|
|
109
|
-
bytes = 0;
|
|
110
|
-
}
|
|
111
|
-
current.push(entry);
|
|
112
|
-
weight += entryWeight;
|
|
113
|
-
bytes += entryBytes;
|
|
114
|
-
}
|
|
115
|
-
if (current.length > 0)
|
|
116
|
-
chunks.push(current);
|
|
117
|
-
return chunks;
|
|
118
|
-
}
|
|
119
|
-
async run(chunk, attempt) {
|
|
120
|
-
if (this.signal?.aborted) {
|
|
121
|
-
for (const entry of chunk)
|
|
122
|
-
entry.reject(new AbortedError());
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
await this.acquire();
|
|
126
|
-
let results;
|
|
127
|
-
try {
|
|
128
|
-
results = await this.send(chunk.map(entry => entry.item), attempt);
|
|
129
|
-
}
|
|
130
|
-
catch (error) {
|
|
131
|
-
this.release();
|
|
132
|
-
if (error instanceof ChunkTooLargeError && chunk.length > 1) {
|
|
133
|
-
const half = Math.ceil(chunk.length / 2);
|
|
134
|
-
void this.run(chunk.slice(0, half), 1);
|
|
135
|
-
void this.run(chunk.slice(half), 1);
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (error instanceof TransientError && attempt <= this.retries) {
|
|
139
|
-
await this.retryLater(chunk, attempt, error.retryAfterMs);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
const failure = error instanceof Error ? error : new Error(String(error));
|
|
143
|
-
for (const entry of chunk)
|
|
144
|
-
entry.reject(failure);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
this.release();
|
|
148
|
-
const throttled = [];
|
|
149
|
-
let retryAfter;
|
|
150
|
-
chunk.forEach((entry, index) => {
|
|
151
|
-
const result = results[index];
|
|
152
|
-
if (result === undefined) {
|
|
153
|
-
entry.reject(new Error("batch: no result for item"));
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if (result.ok === true) {
|
|
157
|
-
entry.resolve(result.value);
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
if (result.error instanceof TransientError && attempt <= this.retries) {
|
|
161
|
-
throttled.push(entry);
|
|
162
|
-
retryAfter = retryAfter ?? result.error.retryAfterMs;
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
entry.reject(result.error);
|
|
166
|
-
});
|
|
167
|
-
if (throttled.length > 0)
|
|
168
|
-
await this.retryLater(throttled, attempt, retryAfter);
|
|
169
|
-
}
|
|
170
|
-
async retryLater(chunk, attempt, retryAfter) {
|
|
171
|
-
await this.sleep(Math.min(retryAfter ?? this.backoff(attempt), this.maxDelayMs));
|
|
172
|
-
void this.run(chunk, attempt + 1);
|
|
173
|
-
}
|
|
174
|
-
backoff(attempt) {
|
|
175
|
-
const base = this.baseDelayMs * 2 ** (attempt - 1);
|
|
176
|
-
const jitter = base * 0.3 * (Math.random() * 2 - 1);
|
|
177
|
-
return Math.round(base + jitter);
|
|
178
|
-
}
|
|
179
|
-
acquire() {
|
|
180
|
-
if (this.active < this.concurrency) {
|
|
181
|
-
this.active += 1;
|
|
182
|
-
return Promise.resolve();
|
|
183
|
-
}
|
|
184
|
-
return new Promise(resolve => {
|
|
185
|
-
this.waiting.push(() => {
|
|
186
|
-
this.active += 1;
|
|
187
|
-
resolve();
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
release() {
|
|
192
|
-
this.active -= 1;
|
|
193
|
-
const next = this.waiting.shift();
|
|
194
|
-
if (next)
|
|
195
|
-
next();
|
|
196
|
-
}
|
|
197
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { AccountShares, PlacementsContext, ProtocolId } from "./types.js";
|
|
2
|
-
export interface ForAccountOptions {
|
|
3
|
-
/** Restrict to these protocols. Defaults to every registered adapter. */
|
|
4
|
-
protocols?: ProtocolId[];
|
|
5
|
-
}
|
|
6
|
-
export declare class PlacementsClient {
|
|
7
|
-
private readonly ctx;
|
|
8
|
-
constructor(ctx: PlacementsContext);
|
|
9
|
-
/** One vault, one account. */
|
|
10
|
-
forAccount(vaultId: string, account: string, options?: ForAccountOptions): Promise<AccountShares[]>;
|
|
11
|
-
forAccounts(vaultIds: string[], account: string, options?: ForAccountOptions): Promise<AccountShares[]>;
|
|
12
|
-
private sharesForCoin;
|
|
13
|
-
private walletBalance;
|
|
14
|
-
private coveredBalance;
|
|
15
|
-
private placementsForCoin;
|
|
16
|
-
private select;
|
|
17
|
-
}
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { asContractAddress, decodeUint256, encodeBalanceOf } from "./evm.js";
|
|
2
|
-
import { getAdapter, listAdapters } from "./registry.js";
|
|
3
|
-
function reasonOf(error) {
|
|
4
|
-
return error instanceof Error ? error.message : String(error);
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Resolves what one account holds of a vault's shares: in its wallet, wrapped
|
|
8
|
-
* for cover, and deployed elsewhere.
|
|
9
|
-
*
|
|
10
|
-
* A protocol that fails is reported in `failures` rather than thrown, so a
|
|
11
|
-
* single unreachable protocol does not zero an otherwise valid answer.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Whether `account` could be an address on this chain.
|
|
15
|
-
*
|
|
16
|
-
* Only one direction is decidable: a 32-byte sui address fed to
|
|
17
|
-
* `balanceOf(address)` overflows the 20-byte word and the node reverts, so it
|
|
18
|
-
* is certainly not evm. A 20-byte address is a valid short-form sui address,
|
|
19
|
-
* so the reverse cannot be ruled out and is left to the chain to answer.
|
|
20
|
-
*/
|
|
21
|
-
function addressFits(chain, account) {
|
|
22
|
-
const hex = account.trim().replace(/^0x/i, "");
|
|
23
|
-
if (!/^[0-9a-fA-F]+$/.test(hex))
|
|
24
|
-
return false;
|
|
25
|
-
return chain === "evm" ? hex.length <= 40 : hex.length <= 64;
|
|
26
|
-
}
|
|
27
|
-
function unresolvedVault(vaultId, reason) {
|
|
28
|
-
return {
|
|
29
|
-
vaultId,
|
|
30
|
-
coin: { coin: "", chain: { type: "sui" }, decimals: 0 },
|
|
31
|
-
available: "0",
|
|
32
|
-
covered: undefined,
|
|
33
|
-
placements: [],
|
|
34
|
-
failures: [{ protocol: "vault", stage: "discover", reason }],
|
|
35
|
-
unresolved: true
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
export class PlacementsClient {
|
|
39
|
-
constructor(ctx) {
|
|
40
|
-
this.ctx = ctx;
|
|
41
|
-
}
|
|
42
|
-
/** One vault, one account. */
|
|
43
|
-
async forAccount(vaultId, account, options = {}) {
|
|
44
|
-
if (!this.ctx.vaults)
|
|
45
|
-
throw new Error("no vault resolver configured");
|
|
46
|
-
const coins = await this.ctx.vaults.coinsForVault(vaultId);
|
|
47
|
-
return Promise.all(coins.map(coin => this.sharesForCoin(vaultId, coin, account, options)));
|
|
48
|
-
}
|
|
49
|
-
async forAccounts(vaultIds, account, options = {}) {
|
|
50
|
-
if (!this.ctx.vaults)
|
|
51
|
-
throw new Error("no vault resolver configured");
|
|
52
|
-
const vaults = this.ctx.vaults;
|
|
53
|
-
const resolved = await Promise.all(vaultIds.map(async (vaultId) => {
|
|
54
|
-
try {
|
|
55
|
-
const coins = await vaults.coinsForVault(vaultId);
|
|
56
|
-
if (!Array.isArray(coins) || coins.length === 0) {
|
|
57
|
-
return {
|
|
58
|
-
vaultId,
|
|
59
|
-
coins: undefined,
|
|
60
|
-
reason: "resolver returned no coins"
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
return { vaultId, coins };
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
return { vaultId, coins: undefined, reason: reasonOf(error) };
|
|
67
|
-
}
|
|
68
|
-
}));
|
|
69
|
-
return Promise.all(resolved.flatMap(entry => entry.coins
|
|
70
|
-
? entry.coins.map(coin => this.sharesForCoin(entry.vaultId, coin, account, options))
|
|
71
|
-
: [
|
|
72
|
-
Promise.resolve(unresolvedVault(entry.vaultId, entry.reason ?? ""))
|
|
73
|
-
]));
|
|
74
|
-
}
|
|
75
|
-
async sharesForCoin(vaultId, coin, account, options) {
|
|
76
|
-
const failures = [];
|
|
77
|
-
// A vault on several chains issues a coin on each, so for any one
|
|
78
|
-
// account all but one of them belongs to a wallet it does not have.
|
|
79
|
-
// Holding none of it is the true answer, and cheaper than asking.
|
|
80
|
-
if (!addressFits(coin.chain.type, account)) {
|
|
81
|
-
return {
|
|
82
|
-
vaultId,
|
|
83
|
-
coin,
|
|
84
|
-
available: "0",
|
|
85
|
-
covered: undefined,
|
|
86
|
-
placements: [],
|
|
87
|
-
failures
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
const [available, covered, placements] = await Promise.all([
|
|
91
|
-
this.walletBalance(coin, account).catch(error => {
|
|
92
|
-
failures.push({
|
|
93
|
-
protocol: "wallet",
|
|
94
|
-
stage: "read",
|
|
95
|
-
coin: coin.coin,
|
|
96
|
-
reason: reasonOf(error)
|
|
97
|
-
});
|
|
98
|
-
return "0";
|
|
99
|
-
}),
|
|
100
|
-
this.coveredBalance(coin, account).catch(error => {
|
|
101
|
-
failures.push({
|
|
102
|
-
protocol: "opencover",
|
|
103
|
-
stage: "read",
|
|
104
|
-
coin: coin.coin,
|
|
105
|
-
reason: reasonOf(error)
|
|
106
|
-
});
|
|
107
|
-
return undefined;
|
|
108
|
-
}),
|
|
109
|
-
this.placementsForCoin(coin, account, options, failures)
|
|
110
|
-
]);
|
|
111
|
-
return { vaultId, coin, available, covered, placements, failures };
|
|
112
|
-
}
|
|
113
|
-
async walletBalance(coin, account) {
|
|
114
|
-
if (coin.chain.type === "sui") {
|
|
115
|
-
if (!this.ctx.sui)
|
|
116
|
-
throw new Error("no sui reader configured");
|
|
117
|
-
return this.ctx.sui.balance(account, coin.coin);
|
|
118
|
-
}
|
|
119
|
-
if (!this.ctx.evm)
|
|
120
|
-
throw new Error("no evm reader configured");
|
|
121
|
-
const chainId = coin.chain.chainId;
|
|
122
|
-
if (chainId === undefined)
|
|
123
|
-
throw new Error(`${coin.coin} has no chainId`);
|
|
124
|
-
const raw = await this.ctx.evm.call(chainId, asContractAddress(coin.coin), encodeBalanceOf(account), coin.rpcUrl);
|
|
125
|
-
return decodeUint256(raw).toString();
|
|
126
|
-
}
|
|
127
|
-
async coveredBalance(coin, account) {
|
|
128
|
-
const coverVault = await this.ctx.vaults?.coverVault?.(coin);
|
|
129
|
-
if (!coverVault)
|
|
130
|
-
return undefined;
|
|
131
|
-
if (!this.ctx.evm)
|
|
132
|
-
throw new Error("no evm reader configured");
|
|
133
|
-
const chainId = coin.chain.chainId;
|
|
134
|
-
if (chainId === undefined)
|
|
135
|
-
throw new Error(`${coin.coin} has no chainId`);
|
|
136
|
-
const raw = await this.ctx.evm.call(chainId, asContractAddress(coverVault), encodeBalanceOf(account), coin.rpcUrl);
|
|
137
|
-
return decodeUint256(raw).toString();
|
|
138
|
-
}
|
|
139
|
-
async placementsForCoin(coin, account, options, failures) {
|
|
140
|
-
const adapters = this.select(options.protocols, failures).filter(adapter => adapter.chain === coin.chain.type);
|
|
141
|
-
const discovered = await Promise.allSettled(adapters.map(adapter => adapter.discover(coin, this.ctx)));
|
|
142
|
-
const jobs = [];
|
|
143
|
-
discovered.forEach((result, index) => {
|
|
144
|
-
const adapter = adapters[index];
|
|
145
|
-
if (result.status === "rejected") {
|
|
146
|
-
failures.push({
|
|
147
|
-
protocol: adapter.id,
|
|
148
|
-
stage: "discover",
|
|
149
|
-
coin: coin.coin,
|
|
150
|
-
reason: reasonOf(result.reason)
|
|
151
|
-
});
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
if (result.value.length > 0)
|
|
155
|
-
jobs.push({ adapter, refs: result.value });
|
|
156
|
-
});
|
|
157
|
-
// One read per adapter rather than per venue, so an adapter can batch
|
|
158
|
-
// every pointer it owns into as few chain round-trips as it can manage.
|
|
159
|
-
const read = await Promise.allSettled(jobs.map(job => job.adapter.read(job.refs, account, this.ctx)));
|
|
160
|
-
const placements = [];
|
|
161
|
-
read.forEach((result, index) => {
|
|
162
|
-
const { adapter } = jobs[index];
|
|
163
|
-
if (result.status === "rejected") {
|
|
164
|
-
failures.push({
|
|
165
|
-
protocol: adapter.id,
|
|
166
|
-
stage: "read",
|
|
167
|
-
coin: coin.coin,
|
|
168
|
-
reason: reasonOf(result.reason)
|
|
169
|
-
});
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
placements.push(...result.value);
|
|
173
|
-
});
|
|
174
|
-
return placements;
|
|
175
|
-
}
|
|
176
|
-
select(protocols, failures) {
|
|
177
|
-
if (!protocols)
|
|
178
|
-
return listAdapters();
|
|
179
|
-
const selected = [];
|
|
180
|
-
for (const id of protocols) {
|
|
181
|
-
const adapter = getAdapter(id);
|
|
182
|
-
if (!adapter) {
|
|
183
|
-
failures.push({
|
|
184
|
-
protocol: id,
|
|
185
|
-
stage: "discover",
|
|
186
|
-
reason: "no adapter registered"
|
|
187
|
-
});
|
|
188
|
-
continue;
|
|
189
|
-
}
|
|
190
|
-
selected.push(adapter);
|
|
191
|
-
}
|
|
192
|
-
return selected;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { EvmReader } from "./types.js";
|
|
2
|
-
import { TransportRequest } from "./batch.js";
|
|
3
|
-
export type { TransportRequest } from "./batch.js";
|
|
4
|
-
export declare function encodeBalanceOf(owner: string): string;
|
|
5
|
-
export declare function asContractAddress(address: string): string;
|
|
6
|
-
export declare function decodeUint256(hex: string): bigint;
|
|
7
|
-
export interface JsonRpcEvmReaderOptions {
|
|
8
|
-
maxCalls?: number;
|
|
9
|
-
concurrency?: number;
|
|
10
|
-
retries?: number;
|
|
11
|
-
baseDelayMs?: number;
|
|
12
|
-
maxDelayMs?: number;
|
|
13
|
-
sleep?: (ms: number) => Promise<void>;
|
|
14
|
-
fetch?: typeof globalThis.fetch;
|
|
15
|
-
signal?: AbortSignal;
|
|
16
|
-
onRequest?: (request: TransportRequest) => void;
|
|
17
|
-
multicall?: boolean;
|
|
18
|
-
}
|
|
19
|
-
interface EvmCall {
|
|
20
|
-
to: string;
|
|
21
|
-
data: string;
|
|
22
|
-
}
|
|
23
|
-
export declare const MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
24
|
-
export declare function encodeAggregate3(calls: EvmCall[]): string;
|
|
25
|
-
export declare function decodeAggregate3(data: string, count: number): {
|
|
26
|
-
success: boolean;
|
|
27
|
-
data: string;
|
|
28
|
-
}[];
|
|
29
|
-
export declare function jsonRpcEvmReader(endpoints?: Record<number, string>, options?: JsonRpcEvmReaderOptions): EvmReader;
|