aftermath-ts-sdk 1.2.67 → 1.2.69
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.
|
@@ -20,6 +20,11 @@ export declare class CoinApi {
|
|
|
20
20
|
coinAmounts: Balance[];
|
|
21
21
|
isSponsoredTx?: boolean;
|
|
22
22
|
}) => Promise<TransactionObjectArgument[]>;
|
|
23
|
+
fetchCoinsWithAtLeastAmount: (inputs: {
|
|
24
|
+
walletAddress: SuiAddress;
|
|
25
|
+
coinType: CoinType;
|
|
26
|
+
coinAmount: Balance;
|
|
27
|
+
}) => Promise<CoinStruct[]>;
|
|
23
28
|
fetchAllCoins: (inputs: {
|
|
24
29
|
walletAddress: SuiAddress;
|
|
25
30
|
coinType: CoinType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coinApi.d.ts","sourceRoot":"","sources":["../../../../src/packages/coin/api/coinApi.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,WAAW,EACX,yBAAyB,EACzB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAY,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEzE,OAAO,EAAE,UAAU,EAAkB,MAAM,oBAAoB,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAG/D,qBAAa,OAAO;IAKP,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,YAAY;IAM5C,qBAAqB,WAAkB;QAC7C,EAAE,EAAE,WAAW,GAAG,gBAAgB,CAAC;QACnC,aAAa,EAAE,UAAU,CAAC;QAC1B,QAAQ,EAAE,QAAQ,CAAC;QACnB,UAAU,EAAE,OAAO,CAAC;QACpB,aAAa,CAAC,EAAE,OAAO,CAAC;KACxB,KAAG,QAAQ,yBAAyB,CAAC,CAcpC;IAEK,sBAA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AAQ,EAAE,CAAC;QACtB,WAAW,EAAE,OAAO,EAAE,CAAC;QACvB,aAAa,CAAC,EAAE,OAAO,CAAC;KACxB,KAAG,QAAQ,yBAAyB,EAAE,CAAC,CA8BtC;IAEK,2BAA2B,WAAkB;QACnD,aAAa,EAAE,UAAU,CAAC;QAC1B,QAAQ,EAAE,QAAQ,CAAC;QACnB,UAAU,EAAE,OAAO,CAAC;KACpB,KAAG,QAAQ,UAAU,EAAE,CAAC,CAsCvB;IAGK,aAAa,WAAkB;QACrC,aAAa,EAAE,UAAU,CAAC;QAC1B,QAAQ,EAAE,QAAQ,CAAC;KAEnB,KAAG,QAAQ,UAAU,EAAE,CAAC,CAiCvB;IAMF,OAAO,CAAC,MAAM,CAAC,gBAAgB,CA+E7B;CACF"}
|
|
@@ -26,7 +26,7 @@ class CoinApi {
|
|
|
26
26
|
this.fetchCoinWithAmountTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
27
27
|
const { tx, walletAddress, coinType, coinAmount, isSponsoredTx } = inputs;
|
|
28
28
|
tx.setSender(walletAddress);
|
|
29
|
-
const coinData = yield this.
|
|
29
|
+
const coinData = yield this.fetchCoinsWithAtLeastAmount(inputs);
|
|
30
30
|
return CoinApi.coinWithAmountTx({
|
|
31
31
|
tx,
|
|
32
32
|
coinData,
|
|
@@ -39,9 +39,7 @@ class CoinApi {
|
|
|
39
39
|
const { tx, walletAddress, coinTypes, coinAmounts, isSponsoredTx } = inputs;
|
|
40
40
|
tx.setSender(walletAddress);
|
|
41
41
|
const allCoinsData = yield Promise.all(coinTypes.map((coinType, index) => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
return this.
|
|
43
|
-
// coinAmount: coinAmounts[index],
|
|
44
|
-
coinType }));
|
|
42
|
+
return this.fetchCoinsWithAtLeastAmount(Object.assign(Object.assign({}, inputs), { coinAmount: coinAmounts[index], coinType }));
|
|
45
43
|
})));
|
|
46
44
|
let coinArgs = [];
|
|
47
45
|
for (const [index, coinData] of allCoinsData.entries()) {
|
|
@@ -56,6 +54,30 @@ class CoinApi {
|
|
|
56
54
|
}
|
|
57
55
|
return coinArgs;
|
|
58
56
|
});
|
|
57
|
+
this.fetchCoinsWithAtLeastAmount = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
let allCoinData = [];
|
|
59
|
+
let cursor = undefined;
|
|
60
|
+
do {
|
|
61
|
+
const paginatedCoins = yield this.Provider.provider.getCoins(Object.assign(Object.assign({}, inputs), { owner: inputs.walletAddress, cursor }));
|
|
62
|
+
const coinData = paginatedCoins.data;
|
|
63
|
+
allCoinData = [...allCoinData, ...coinData];
|
|
64
|
+
if (paginatedCoins.data.length === 0 ||
|
|
65
|
+
!paginatedCoins.hasNextPage ||
|
|
66
|
+
!paginatedCoins.nextCursor) {
|
|
67
|
+
allCoinData.sort((b, a) => Number(BigInt(a.balance) - BigInt(b.balance)));
|
|
68
|
+
let coinDatas = [];
|
|
69
|
+
let sum = BigInt(0);
|
|
70
|
+
for (const coinData of allCoinData) {
|
|
71
|
+
coinDatas.push(coinData);
|
|
72
|
+
sum += BigInt(coinData.balance);
|
|
73
|
+
if (sum >= inputs.coinAmount)
|
|
74
|
+
return coinDatas;
|
|
75
|
+
}
|
|
76
|
+
throw new Error("wallet does not have coins of sufficient balance");
|
|
77
|
+
}
|
|
78
|
+
cursor = paginatedCoins.nextCursor;
|
|
79
|
+
} while (true);
|
|
80
|
+
});
|
|
59
81
|
// fetchCoinsUntilAmountReachedOrEnd
|
|
60
82
|
this.fetchAllCoins = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
61
83
|
let allCoinData = [];
|