@avail-project/ca-common 1.0.0-dev.4 → 1.0.1-beta1
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/cjs/data/chaindata.js +110 -28
- package/dist/cjs/index.js +3 -4
- package/dist/cjs/proto/client.js +48 -0
- package/dist/cjs/proto/definition.js +167 -448
- package/dist/cjs/proto/grpc.js +4 -9
- package/dist/cjs/rff/rff.js +0 -34
- package/dist/cjs/vaultcontracts/vaultcontracts.js +15 -11
- package/dist/cjs/xcs/autochoice.js +255 -0
- package/dist/esm/data/chaindata.js +110 -28
- package/dist/esm/index.js +12 -12
- package/dist/esm/proto/client.js +11 -0
- package/dist/esm/proto/definition.js +167 -448
- package/dist/esm/proto/grpc.js +4 -9
- package/dist/esm/rff/rff.js +0 -34
- package/dist/esm/vaultcontracts/vaultcontracts.js +15 -11
- package/dist/esm/xcs/autochoice.js +254 -0
- package/dist/types/index.d.ts +12 -12
- package/dist/types/proto/client.d.ts +2 -0
- package/dist/types/rff/rff.d.ts +0 -3
- package/dist/types/xcs/autochoice.d.ts +17 -0
- package/package.json +11 -10
- package/dist/cjs/fuelcontracts/ArcanaVault.js +0 -2407
- package/dist/cjs/fuelcontracts/ArcanaVaultFactory.js +0 -18
- package/dist/cjs/fuelcontracts/common.js +0 -3
- package/dist/cjs/fuelcontracts/index.js +0 -6
- package/dist/cjs/rff/fuel.js +0 -27
- package/dist/esm/fuelcontracts/ArcanaVault.js +0 -2402
- package/dist/esm/fuelcontracts/ArcanaVaultFactory.js +0 -14
- package/dist/esm/fuelcontracts/common.js +0 -2
- package/dist/esm/fuelcontracts/index.js +0 -3
- package/dist/esm/rff/fuel.js +0 -23
- package/dist/types/fuelcontracts/ArcanaVault.d.ts +0 -448
- package/dist/types/fuelcontracts/ArcanaVaultFactory.d.ts +0 -8
- package/dist/types/fuelcontracts/common.d.ts +0 -23
- package/dist/types/fuelcontracts/index.d.ts +0 -3
- package/dist/types/rff/fuel.d.ts +0 -4
package/dist/esm/proto/grpc.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
2
2
|
// versions:
|
|
3
|
-
// protoc-gen-ts_proto v2.
|
|
3
|
+
// protoc-gen-ts_proto v2.8.3
|
|
4
4
|
// protoc v6.32.1
|
|
5
5
|
// source: grpc.proto
|
|
6
6
|
/* eslint-disable */
|
|
@@ -259,19 +259,14 @@ export class GrpcWebImpl {
|
|
|
259
259
|
unary(methodDesc, _request, metadata) {
|
|
260
260
|
const request = { ..._request, ...methodDesc.requestType };
|
|
261
261
|
const maybeCombinedMetadata = metadata && this.options.metadata
|
|
262
|
-
? new BrowserHeaders({
|
|
263
|
-
|
|
264
|
-
...metadata?.headersMap,
|
|
265
|
-
})
|
|
266
|
-
: (metadata ?? this.options.metadata);
|
|
262
|
+
? new BrowserHeaders({ ...this.options?.metadata.headersMap, ...metadata?.headersMap })
|
|
263
|
+
: metadata ?? this.options.metadata;
|
|
267
264
|
return new Promise((resolve, reject) => {
|
|
268
265
|
grpc.unary(methodDesc, {
|
|
269
266
|
request,
|
|
270
267
|
host: this.host,
|
|
271
268
|
metadata: maybeCombinedMetadata ?? {},
|
|
272
|
-
...(this.options.transport !== undefined
|
|
273
|
-
? { transport: this.options.transport }
|
|
274
|
-
: {}),
|
|
269
|
+
...(this.options.transport !== undefined ? { transport: this.options.transport } : {}),
|
|
275
270
|
debug: this.options.debug ?? false,
|
|
276
271
|
onEnd: function (response) {
|
|
277
272
|
if (response.status === grpc.Code.OK) {
|
package/dist/esm/rff/rff.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { bytesToBigInt } from "viem";
|
|
2
|
-
import { BN } from "fuels";
|
|
3
2
|
import { ezPadTo32Hex } from "../data";
|
|
4
|
-
import { protobufUniverseToFuelUniverse } from "./fuel";
|
|
5
3
|
export class OmniversalRFF {
|
|
6
4
|
protobufRFF;
|
|
7
5
|
evmRFF;
|
|
8
|
-
fuelRFF;
|
|
9
6
|
constructor(protobufRFF) {
|
|
10
7
|
this.protobufRFF = protobufRFF;
|
|
11
8
|
}
|
|
@@ -35,37 +32,6 @@ export class OmniversalRFF {
|
|
|
35
32
|
}
|
|
36
33
|
return this.evmRFF;
|
|
37
34
|
}
|
|
38
|
-
asFuelRFF() {
|
|
39
|
-
if (this.fuelRFF == null) {
|
|
40
|
-
this.fuelRFF = {
|
|
41
|
-
sources: this.protobufRFF.sources.map((s) => ({
|
|
42
|
-
universe: protobufUniverseToFuelUniverse(s.universe),
|
|
43
|
-
chain_id: new BN(s.chainID),
|
|
44
|
-
asset_id: {
|
|
45
|
-
bits: ezPadTo32Hex(s.contractAddress),
|
|
46
|
-
},
|
|
47
|
-
value: new BN(s.value),
|
|
48
|
-
})),
|
|
49
|
-
destination_chain_id: new BN(this.protobufRFF.destinationChainID),
|
|
50
|
-
destination_universe: protobufUniverseToFuelUniverse(this.protobufRFF.destinationUniverse),
|
|
51
|
-
destinations: this.protobufRFF.destinations.map((d) => ({
|
|
52
|
-
asset_id: {
|
|
53
|
-
bits: ezPadTo32Hex(d.contractAddress),
|
|
54
|
-
},
|
|
55
|
-
value: new BN(d.value),
|
|
56
|
-
})),
|
|
57
|
-
expiry: new BN(this.protobufRFF.expiry.toBytesBE()),
|
|
58
|
-
nonce: new BN(this.protobufRFF.nonce),
|
|
59
|
-
parties: this.protobufRFF.signatureData.map((sd) => ({
|
|
60
|
-
universe: protobufUniverseToFuelUniverse(sd.universe),
|
|
61
|
-
address: {
|
|
62
|
-
bits: ezPadTo32Hex(sd.address),
|
|
63
|
-
},
|
|
64
|
-
})),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return this.fuelRFF;
|
|
68
|
-
}
|
|
69
35
|
asProtobufRFF() {
|
|
70
36
|
return this.protobufRFF;
|
|
71
37
|
}
|
|
@@ -12,24 +12,28 @@ const dataSets = new Map([
|
|
|
12
12
|
[
|
|
13
13
|
Environment.FOLLY,
|
|
14
14
|
[
|
|
15
|
+
[
|
|
16
|
+
new OmniversalChainID(Universe.ETHEREUM, 11155111),
|
|
17
|
+
"0xd579B76e3f51884c50eB8e8efdef5C593666B8fb",
|
|
18
|
+
],
|
|
15
19
|
[
|
|
16
20
|
new OmniversalChainID(Universe.ETHEREUM, 421614),
|
|
17
|
-
"
|
|
21
|
+
"0x10B69f0E3c21C1187526940A615959E9ee6012F9",
|
|
18
22
|
],
|
|
19
23
|
[
|
|
20
24
|
new OmniversalChainID(Universe.ETHEREUM, 11155420),
|
|
21
|
-
"
|
|
25
|
+
"0x10B69f0E3c21C1187526940A615959E9ee6012F9",
|
|
22
26
|
],
|
|
23
27
|
[
|
|
24
|
-
new OmniversalChainID(Universe.ETHEREUM,
|
|
25
|
-
"
|
|
28
|
+
new OmniversalChainID(Universe.ETHEREUM, 84532),
|
|
29
|
+
"0xA7458040272226378397C3036eda862D60C3b307",
|
|
26
30
|
],
|
|
27
31
|
[
|
|
28
|
-
new OmniversalChainID(Universe.ETHEREUM,
|
|
29
|
-
"
|
|
32
|
+
new OmniversalChainID(Universe.ETHEREUM, 5115),
|
|
33
|
+
"0x10B69f0E3c21C1187526940A615959E9ee6012F9",
|
|
30
34
|
],
|
|
31
35
|
[
|
|
32
|
-
new OmniversalChainID(Universe.ETHEREUM,
|
|
36
|
+
new OmniversalChainID(Universe.ETHEREUM, 80002),
|
|
33
37
|
"0xEFF0C81eC6D7c2a3B924e98B65303DDaa3030a81",
|
|
34
38
|
],
|
|
35
39
|
[
|
|
@@ -57,6 +61,10 @@ const dataSets = new Map([
|
|
|
57
61
|
new OmniversalChainID(Universe.ETHEREUM, 8453),
|
|
58
62
|
"0x111111eA4f8BdfB5AE22c37ebC3eE17b82072F57",
|
|
59
63
|
],
|
|
64
|
+
[
|
|
65
|
+
new OmniversalChainID(Universe.ETHEREUM, 4326),
|
|
66
|
+
"0x10B69f0E3c21C1187526940A615959E9ee6012F9",
|
|
67
|
+
],
|
|
60
68
|
[
|
|
61
69
|
new OmniversalChainID(Universe.ETHEREUM, 534352),
|
|
62
70
|
"0x111111eA4f8BdfB5AE22c37ebC3eE17b82072F57",
|
|
@@ -122,10 +130,6 @@ const dataSets = new Map([
|
|
|
122
130
|
new OmniversalChainID(Universe.ETHEREUM, 143),
|
|
123
131
|
"0xC0DED5d7F424276c821AF21F68E1e663bC671C3D",
|
|
124
132
|
],
|
|
125
|
-
[
|
|
126
|
-
new OmniversalChainID(Universe.FUEL, 9889),
|
|
127
|
-
"0xe2586f908cc885e630cec6d8d578f02e6ade66983baf23f82757be502127dfb1",
|
|
128
|
-
],
|
|
129
133
|
],
|
|
130
134
|
],
|
|
131
135
|
[
|
|
@@ -56,6 +56,259 @@ export async function aggregateAggregators(requests, aggregators, mode) {
|
|
|
56
56
|
}
|
|
57
57
|
return final;
|
|
58
58
|
}
|
|
59
|
+
/*
|
|
60
|
+
In original autoSelectSources:
|
|
61
|
+
Assets = [1 ETH, 1 COT, 1 ETH, 1 USDT, 1 COT]
|
|
62
|
+
Output = 4
|
|
63
|
+
|
|
64
|
+
First loop that just removes cot:
|
|
65
|
+
quoteAssets = [1 ETH, 1 ETH, 1 USDT]
|
|
66
|
+
Output = 4
|
|
67
|
+
|
|
68
|
+
Outside the function we can just remove all COT's and assume those as being used
|
|
69
|
+
but that's incorrect as we want to use assets in exact order as holdings array.
|
|
70
|
+
We can't remove only COT's that are going to be used because we don't know which ones are going
|
|
71
|
+
to get used.
|
|
72
|
+
|
|
73
|
+
Proposed solution:
|
|
74
|
+
It should actually use assets in exact order, so it cant be done outside the function
|
|
75
|
+
1. The function has to keep an order of assets, separate out COT and non-COT assets.
|
|
76
|
+
2. Get quote for non-COT assets, then loop over the original order
|
|
77
|
+
3. Used either COT or quote depending on original order
|
|
78
|
+
4. Send back quotes and COT's used
|
|
79
|
+
|
|
80
|
+
Alg:
|
|
81
|
+
Assets = [1 ETH, 1 COT, 1 ETH, 1 USDT, 1 COT]
|
|
82
|
+
Output = 4
|
|
83
|
+
|
|
84
|
+
1. separate into two with indexes:
|
|
85
|
+
quotes = [(1 ETH, 0), (1 ETH, 2), (1 USDT, 3)]
|
|
86
|
+
cots = [(1 COT, 1), (1 COT, 4)]
|
|
87
|
+
|
|
88
|
+
2. Get quotes using only quotes
|
|
89
|
+
3. merge quote cots and sort by order
|
|
90
|
+
4. loop assets (original order):
|
|
91
|
+
if a quote:
|
|
92
|
+
output = output - quote_output_amount
|
|
93
|
+
if a cot:
|
|
94
|
+
output = output - cot_amount
|
|
95
|
+
if output <= 0:
|
|
96
|
+
break
|
|
97
|
+
5. return quotes and assets used.
|
|
98
|
+
*/
|
|
99
|
+
export async function autoSelectSourcesV2(userAddress, holdings, outputRequired, aggregators, commonCurrencyID = CurrencyID.USDC) {
|
|
100
|
+
// Assumption: Holding is already sorted in usage priority
|
|
101
|
+
console.log("XCS | SSV2:", {
|
|
102
|
+
holdings,
|
|
103
|
+
outputRequired: outputRequired.toFixed(),
|
|
104
|
+
});
|
|
105
|
+
const fullLiquidationQuotes = [];
|
|
106
|
+
const cotList = [];
|
|
107
|
+
for (const [idx, holding] of holdings.entries()) {
|
|
108
|
+
const chain = ChaindataMap.get(holding.chainID);
|
|
109
|
+
if (chain == null) {
|
|
110
|
+
throw new AutoSelectionError("Chain not found");
|
|
111
|
+
}
|
|
112
|
+
const correspondingCurrency = chain.Currencies.find((cur) => cur.currencyID === commonCurrencyID);
|
|
113
|
+
if (correspondingCurrency == null) {
|
|
114
|
+
console.log("XCS | SS | Skipping because correspondingCurrency is null", {
|
|
115
|
+
chain,
|
|
116
|
+
correspondingCurrency,
|
|
117
|
+
});
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (Buffer.compare(holding.tokenAddress, correspondingCurrency.tokenAddress) === 0) {
|
|
121
|
+
const normalizedAmount = new Decimal(holding.amount).div(Decimal.pow(10, correspondingCurrency.decimals));
|
|
122
|
+
cotList.push({
|
|
123
|
+
amount: normalizedAmount,
|
|
124
|
+
idx,
|
|
125
|
+
chainID: holding.chainID,
|
|
126
|
+
currency: correspondingCurrency,
|
|
127
|
+
originalHolding: holding,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
fullLiquidationQuotes.push({
|
|
132
|
+
req: {
|
|
133
|
+
userAddress,
|
|
134
|
+
type: QuoteType.EXACT_IN,
|
|
135
|
+
chain: chain.ChainID,
|
|
136
|
+
inputToken: holding.tokenAddress,
|
|
137
|
+
inputAmount: holding.amount,
|
|
138
|
+
outputToken: correspondingCurrency.tokenAddress,
|
|
139
|
+
seriousness: QuoteSeriousness.PRICE_SURVEY,
|
|
140
|
+
},
|
|
141
|
+
originalHolding: holding,
|
|
142
|
+
cur: correspondingCurrency,
|
|
143
|
+
idx,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Check if continuous COTs from the start can cover the entire requirement
|
|
148
|
+
// We can skip quoting unused holdings
|
|
149
|
+
if (cotList.length > 0 && cotList[0].idx === 0) {
|
|
150
|
+
let continuousCOTAmount = new Decimal(0);
|
|
151
|
+
let continuousCount = 0;
|
|
152
|
+
for (const cot of cotList) {
|
|
153
|
+
// only consecutive cots allowed, otherwise we need to go to quoting
|
|
154
|
+
if (cot.idx !== continuousCount)
|
|
155
|
+
break;
|
|
156
|
+
continuousCOTAmount = continuousCOTAmount.add(cot.amount);
|
|
157
|
+
continuousCount++;
|
|
158
|
+
if (continuousCOTAmount.gte(outputRequired)) {
|
|
159
|
+
console.log("XCS | SS | Continuous COTs can satisfy requirement, skipping quotes");
|
|
160
|
+
const usedCOTs = [];
|
|
161
|
+
let remainder = outputRequired;
|
|
162
|
+
for (let i = 0; i < continuousCount; i++) {
|
|
163
|
+
const cot = cotList[i];
|
|
164
|
+
const amountToUse = Decimal.min(remainder, cot.amount);
|
|
165
|
+
usedCOTs.push({
|
|
166
|
+
originalHolding: cot.originalHolding,
|
|
167
|
+
amountUsed: amountToUse,
|
|
168
|
+
idx: cot.idx,
|
|
169
|
+
cur: cot.currency,
|
|
170
|
+
});
|
|
171
|
+
remainder = remainder.minus(amountToUse);
|
|
172
|
+
if (remainder.lte(0))
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
console.log("XCS | SS | Early return with continuous COTs:", {
|
|
176
|
+
cots: usedCOTs,
|
|
177
|
+
});
|
|
178
|
+
return { quotes: [], usedCOTs };
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const processingQueue = [];
|
|
183
|
+
// Add COT holdings
|
|
184
|
+
for (const cot of cotList) {
|
|
185
|
+
processingQueue.push({
|
|
186
|
+
idx: cot.idx,
|
|
187
|
+
isCOT: true,
|
|
188
|
+
cotData: cot,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
// Add non-COT holdings
|
|
192
|
+
for (let i = 0; i < fullLiquidationQuotes.length; i++) {
|
|
193
|
+
processingQueue.push({
|
|
194
|
+
idx: fullLiquidationQuotes[i].idx,
|
|
195
|
+
isCOT: false,
|
|
196
|
+
quoteData: fullLiquidationQuotes[i],
|
|
197
|
+
responseIdx: i,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
// Sort by original index to maintain priority
|
|
201
|
+
processingQueue.sort((a, b) => a.idx - b.idx);
|
|
202
|
+
const responses = await aggregateAggregators(fullLiquidationQuotes.map((fq) => fq.req), aggregators, 0 /* AggregateAggregatorsMode.MaximizeOutput */);
|
|
203
|
+
console.log("XCS | SS | Responses:", responses);
|
|
204
|
+
const final = [];
|
|
205
|
+
const usedCOTs = [];
|
|
206
|
+
let remainder = outputRequired;
|
|
207
|
+
for (const item of processingQueue) {
|
|
208
|
+
if (remainder.lte(0)) {
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
if (item.isCOT) {
|
|
212
|
+
// Process COT holding - direct usage, no quote
|
|
213
|
+
const { cotData } = item;
|
|
214
|
+
const amountToUse = Decimal.min(remainder, cotData.amount);
|
|
215
|
+
usedCOTs.push({
|
|
216
|
+
originalHolding: cotData.originalHolding,
|
|
217
|
+
amountUsed: amountToUse,
|
|
218
|
+
idx: cotData.idx,
|
|
219
|
+
cur: cotData.currency,
|
|
220
|
+
});
|
|
221
|
+
remainder = remainder.minus(amountToUse);
|
|
222
|
+
console.log("XCS | SS | Used COT", {
|
|
223
|
+
idx: cotData.idx,
|
|
224
|
+
amountToUse: amountToUse.toFixed(),
|
|
225
|
+
remainder: remainder.toFixed(),
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
// Process non-COT holding - use existing quote logic
|
|
230
|
+
const { quoteData, responseIdx } = item;
|
|
231
|
+
const { quote: resp, aggregator: agg } = responses[responseIdx];
|
|
232
|
+
if (resp == null) {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
console.log("XCS | SS | 1", {
|
|
236
|
+
i: responseIdx,
|
|
237
|
+
idx: quoteData.idx,
|
|
238
|
+
remainder,
|
|
239
|
+
q: quoteData,
|
|
240
|
+
resp,
|
|
241
|
+
agg,
|
|
242
|
+
});
|
|
243
|
+
const divisor = Decimal.pow(10, quoteData.cur.decimals);
|
|
244
|
+
const oamD = Decimal.div(resp.outputAmountMinimum, divisor);
|
|
245
|
+
if (oamD.gt(remainder)) {
|
|
246
|
+
const indicativePrice = Decimal.div(resp.inputAmount, resp.outputAmountMinimum);
|
|
247
|
+
const userBal = new Decimal(quoteData.originalHolding.amount);
|
|
248
|
+
// remainder is the output we want, so the input amount is remainder × indicativePrice
|
|
249
|
+
let expectedInput = Decimal.min(remainder.mul(divisor).mul(indicativePrice).mul(safetyMultiplier), userBal);
|
|
250
|
+
while (true) {
|
|
251
|
+
console.log("XCS | SS | 2⒜", {
|
|
252
|
+
indicativePrice,
|
|
253
|
+
expectedInput,
|
|
254
|
+
userBal,
|
|
255
|
+
});
|
|
256
|
+
const adequateQuoteResult = await aggregateAggregators([
|
|
257
|
+
{
|
|
258
|
+
...quoteData.req,
|
|
259
|
+
seriousness: QuoteSeriousness.SERIOUS,
|
|
260
|
+
inputAmount: convertDecimalToBigInt(expectedInput),
|
|
261
|
+
},
|
|
262
|
+
], aggregators, 0 /* AggregateAggregatorsMode.MaximizeOutput */);
|
|
263
|
+
if (adequateQuoteResult.length !== 1) {
|
|
264
|
+
throw new AutoSelectionError("???");
|
|
265
|
+
}
|
|
266
|
+
const adequateQuote = adequateQuoteResult[0];
|
|
267
|
+
if (adequateQuote.quote == null) {
|
|
268
|
+
throw new AutoSelectionError("Couldn't get buy quote");
|
|
269
|
+
}
|
|
270
|
+
console.log("XCS | SS | 2⒜⑴", {
|
|
271
|
+
adequateQuote,
|
|
272
|
+
});
|
|
273
|
+
const oam2D = Decimal.div(adequateQuote.quote.outputAmountMinimum, divisor);
|
|
274
|
+
if (oam2D.gte(remainder)) {
|
|
275
|
+
final.push({
|
|
276
|
+
...quoteData,
|
|
277
|
+
quote: adequateQuote.quote,
|
|
278
|
+
agg: adequateQuote.aggregator,
|
|
279
|
+
});
|
|
280
|
+
remainder = remainder.minus(oam2D);
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
else if (expectedInput.eq(userBal)) {
|
|
284
|
+
throw new AutoSelectionError("Holding was supposedly enough to meet the full requirement but ceased to be so subsequently");
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
expectedInput = Decimal.min(expectedInput.mul(safetyMultiplier), userBal); // try again with higher amount
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
console.log("XCS | SS | 2⒝", resp);
|
|
293
|
+
final.push({
|
|
294
|
+
...quoteData,
|
|
295
|
+
quote: resp,
|
|
296
|
+
agg,
|
|
297
|
+
});
|
|
298
|
+
remainder = remainder.minus(convertBigIntToDecimal(resp.outputAmountMinimum).div(divisor));
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
console.log("XCS | SS | 3⒜", {
|
|
303
|
+
remainder,
|
|
304
|
+
final,
|
|
305
|
+
});
|
|
306
|
+
if (remainder.gt(0)) {
|
|
307
|
+
throw new AutoSelectionError("Failed to accumulate enough swaps to meet requirement");
|
|
308
|
+
}
|
|
309
|
+
console.log("XCS | SS | Final:", { quotes: final, cots: usedCOTs });
|
|
310
|
+
return { quotes: final, usedCOTs };
|
|
311
|
+
}
|
|
59
312
|
export async function autoSelectSources(userAddress, holdings, outputRequired, aggregators, collectionFees, commonCurrencyID = CurrencyID.USDC) {
|
|
60
313
|
console.log("XCS | SS | Holdings:", holdings);
|
|
61
314
|
const groupedByChainID = groupBy(holdings, (h) => bytesToHex(h.chainID.toBytes()));
|
|
@@ -205,6 +458,7 @@ export async function determineDestinationSwaps(userAddress, chainID, requiremen
|
|
|
205
458
|
if (COT == null) {
|
|
206
459
|
throw new AutoSelectionError("COT not present on the destination chain");
|
|
207
460
|
}
|
|
461
|
+
// FIXME: Replace with oracle usage - should reduce time.
|
|
208
462
|
// what happens if we happen to sell the requirement for the COT, what would the amount be?
|
|
209
463
|
const fullLiquidationQR = {
|
|
210
464
|
type: QuoteType.EXACT_IN,
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import "./_polyfill";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export {
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
2
|
+
export * from "./proto/definition";
|
|
3
|
+
export { QueryClientImpl, Query, GrpcWebError, GrpcWebImpl, } from "./proto/grpc";
|
|
4
|
+
export { createGrpcWebImpl } from "./proto/client";
|
|
5
|
+
export * from "./data";
|
|
6
|
+
export * from "./vaultcontracts";
|
|
7
|
+
export * from "./permitutils";
|
|
8
|
+
export * from "./xcs";
|
|
9
|
+
export * from "./cosmos";
|
|
10
|
+
export * from "./rff/rff";
|
|
11
|
+
export * from "./types";
|
|
12
|
+
export * from "./balances/ub-api";
|
|
13
|
+
export * from "./evmabi";
|
package/dist/types/rff/rff.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { RequestForFunds } from "../proto/definition";
|
|
2
2
|
import { type EVMRFF } from "../vaultcontracts";
|
|
3
|
-
import { RequestInput as FuelRFF } from "../fuelcontracts/ArcanaVault";
|
|
4
3
|
export declare class OmniversalRFF {
|
|
5
4
|
readonly protobufRFF: RequestForFunds;
|
|
6
5
|
private evmRFF;
|
|
7
|
-
private fuelRFF;
|
|
8
6
|
constructor(protobufRFF: RequestForFunds);
|
|
9
7
|
asEVMRFF(): EVMRFF;
|
|
10
|
-
asFuelRFF(): FuelRFF;
|
|
11
8
|
asProtobufRFF(): RequestForFunds;
|
|
12
9
|
}
|
|
@@ -21,6 +21,23 @@ export declare function aggregateAggregators(requests: (QuoteRequestExactInput |
|
|
|
21
21
|
quote: Quote | null;
|
|
22
22
|
aggregator: Aggregator;
|
|
23
23
|
}[]>;
|
|
24
|
+
export declare function autoSelectSourcesV2(userAddress: Bytes, holdings: Holding[], outputRequired: Decimal, aggregators: Aggregator[], commonCurrencyID?: CurrencyID): Promise<{
|
|
25
|
+
quotes: ({
|
|
26
|
+
req: QuoteRequestExactInput;
|
|
27
|
+
originalHolding: Holding;
|
|
28
|
+
cur: Currency;
|
|
29
|
+
idx: number;
|
|
30
|
+
} & {
|
|
31
|
+
quote: Quote;
|
|
32
|
+
agg: Aggregator;
|
|
33
|
+
})[];
|
|
34
|
+
usedCOTs: {
|
|
35
|
+
originalHolding: Holding;
|
|
36
|
+
amountUsed: Decimal;
|
|
37
|
+
idx: number;
|
|
38
|
+
cur: Currency;
|
|
39
|
+
}[];
|
|
40
|
+
}>;
|
|
24
41
|
export declare function autoSelectSources(userAddress: Bytes, holdings: Holding[], outputRequired: Decimal, aggregators: Aggregator[], collectionFees: FixedFeeTuple[], commonCurrencyID?: CurrencyID): Promise<({
|
|
25
42
|
req: QuoteRequestExactInput;
|
|
26
43
|
cfee: bigint;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avail-project/ca-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-beta1",
|
|
4
4
|
"description": "common utilities for CA",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -15,11 +15,6 @@
|
|
|
15
15
|
"types": "./dist/types/index.d.ts",
|
|
16
16
|
"require": "./dist/cjs/index.js",
|
|
17
17
|
"import": "./dist/esm/index.js"
|
|
18
|
-
},
|
|
19
|
-
"./fuelcontracts": {
|
|
20
|
-
"types": "./dist/types/fuelcontracts/index.d.ts",
|
|
21
|
-
"require": "./dist/cjs/fuelcontracts/index.js",
|
|
22
|
-
"import": "./dist/esm/fuelcontracts/index.js"
|
|
23
18
|
}
|
|
24
19
|
},
|
|
25
20
|
"scripts": {
|
|
@@ -29,7 +24,9 @@
|
|
|
29
24
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
30
25
|
"lint": "eslint",
|
|
31
26
|
"clean": "rimraf dist/",
|
|
32
|
-
"prepublishOnly": "npm run build"
|
|
27
|
+
"prepublishOnly": "npm run build",
|
|
28
|
+
"release": "release-it",
|
|
29
|
+
"prepare": "npm run build"
|
|
33
30
|
},
|
|
34
31
|
"author": "",
|
|
35
32
|
"license": "MIT",
|
|
@@ -44,6 +41,7 @@
|
|
|
44
41
|
"globals": "^16.3.0",
|
|
45
42
|
"npm-run-all": "^4.1.5",
|
|
46
43
|
"prettier": "^3.6.2",
|
|
44
|
+
"release-it": "^19.2.3",
|
|
47
45
|
"rimraf": "^6.0.1",
|
|
48
46
|
"ts-proto": "^2.7.5",
|
|
49
47
|
"typescript": "^5.8.3"
|
|
@@ -53,16 +51,19 @@
|
|
|
53
51
|
"@cosmjs/stargate": "^0.34.0",
|
|
54
52
|
"axios": "^1.10.0",
|
|
55
53
|
"decimal.js": "^10.6.0",
|
|
56
|
-
"fuels": "^0.101.1",
|
|
57
54
|
"long": "^5.3.2",
|
|
58
|
-
"
|
|
59
|
-
"
|
|
55
|
+
"msgpackr": "^1.11.4",
|
|
56
|
+
"viem": "^2.31.7"
|
|
60
57
|
},
|
|
61
58
|
"dependencies": {
|
|
62
59
|
"@bufbuild/protobuf": "^2.6.0",
|
|
63
60
|
"@improbable-eng/grpc-web": "^0.15.0",
|
|
61
|
+
"@improbable-eng/grpc-web-node-http-transport": "0.15.0",
|
|
64
62
|
"browser-headers": "^0.4.1",
|
|
65
63
|
"es-toolkit": "^1.39.7",
|
|
66
64
|
"tslib": "^2.8.1"
|
|
65
|
+
},
|
|
66
|
+
"repository": {
|
|
67
|
+
"url": "https://github.com/availproject/ca-common"
|
|
67
68
|
}
|
|
68
69
|
}
|