@msafe/sui-app-store 0.0.15 → 0.0.16
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/index.global.js +9 -9
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +130 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +121 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2062,6 +2062,76 @@ function normalizeAddressFilter(address) {
|
|
|
2062
2062
|
return address.length !== 0 ? address.map((addr) => (0, import_utils8.normalizeSuiAddress)(addr)) : void 0;
|
|
2063
2063
|
}
|
|
2064
2064
|
|
|
2065
|
+
// src/apps/mpay/error/NotEnoughBalanceError.ts
|
|
2066
|
+
var NotEnoughBalanceError = class extends MPayError {
|
|
2067
|
+
constructor(coinType, requestAmount, gotAmount) {
|
|
2068
|
+
super(4 /* NotEnoughBalance */, `Not enough balance: ${coinType}`, {
|
|
2069
|
+
context: {
|
|
2070
|
+
coinType,
|
|
2071
|
+
requestAmount,
|
|
2072
|
+
gotAmount
|
|
2073
|
+
}
|
|
2074
|
+
});
|
|
2075
|
+
this.coinType = coinType;
|
|
2076
|
+
this.requestAmount = requestAmount;
|
|
2077
|
+
this.gotAmount = gotAmount;
|
|
2078
|
+
}
|
|
2079
|
+
};
|
|
2080
|
+
|
|
2081
|
+
// src/apps/mpay/sui/iterator/coin.ts
|
|
2082
|
+
var DEF_REQ_PAGE_SIZE = 25;
|
|
2083
|
+
async function getCoinsWithAmount(suiClient, owner, requestAmount, coinType = "0x2::sui::SUI", pageSize = DEF_REQ_PAGE_SIZE) {
|
|
2084
|
+
const it = new OwnedCoinIterator(suiClient, owner, coinType, pageSize);
|
|
2085
|
+
let totalAmount = BigInt(0);
|
|
2086
|
+
const res = [];
|
|
2087
|
+
while (await it.hasNext() && totalAmount < requestAmount) {
|
|
2088
|
+
const val = await it.next();
|
|
2089
|
+
if (!val) {
|
|
2090
|
+
continue;
|
|
2091
|
+
}
|
|
2092
|
+
res.push(val);
|
|
2093
|
+
totalAmount += BigInt(val.balance);
|
|
2094
|
+
}
|
|
2095
|
+
if (totalAmount < requestAmount) {
|
|
2096
|
+
throw new NotEnoughBalanceError(coinType, requestAmount, totalAmount);
|
|
2097
|
+
}
|
|
2098
|
+
return res;
|
|
2099
|
+
}
|
|
2100
|
+
var OwnedCoinIterator = class extends EntryIterator {
|
|
2101
|
+
constructor(suiClient, owner, coinType, reqPageSize) {
|
|
2102
|
+
super(new OwnedCoinRequester(suiClient, owner, coinType, reqPageSize));
|
|
2103
|
+
this.suiClient = suiClient;
|
|
2104
|
+
this.owner = owner;
|
|
2105
|
+
this.coinType = coinType;
|
|
2106
|
+
this.reqPageSize = reqPageSize;
|
|
2107
|
+
}
|
|
2108
|
+
};
|
|
2109
|
+
var OwnedCoinRequester = class {
|
|
2110
|
+
constructor(suiClient, owner, coinType, reqPageSize) {
|
|
2111
|
+
this.suiClient = suiClient;
|
|
2112
|
+
this.owner = owner;
|
|
2113
|
+
this.coinType = coinType;
|
|
2114
|
+
this.reqPageSize = reqPageSize;
|
|
2115
|
+
if (reqPageSize <= 0) {
|
|
2116
|
+
throw new SanityError("Invalid reqPageSize");
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
nextCursor;
|
|
2120
|
+
async doNextRequest() {
|
|
2121
|
+
const res = await this.suiClient.getCoins({
|
|
2122
|
+
owner: this.owner,
|
|
2123
|
+
coinType: this.coinType,
|
|
2124
|
+
cursor: this.nextCursor,
|
|
2125
|
+
limit: this.reqPageSize
|
|
2126
|
+
});
|
|
2127
|
+
this.nextCursor = res.nextCursor;
|
|
2128
|
+
return {
|
|
2129
|
+
data: res.data,
|
|
2130
|
+
hasNext: res.hasNextPage
|
|
2131
|
+
};
|
|
2132
|
+
}
|
|
2133
|
+
};
|
|
2134
|
+
|
|
2065
2135
|
// src/apps/mpay/stream/client.ts
|
|
2066
2136
|
var MSafeAccountAdapter = class {
|
|
2067
2137
|
constructor(msafe) {
|
|
@@ -2077,6 +2147,47 @@ var MSafeAccountAdapter = class {
|
|
|
2077
2147
|
return this.msafe.requestCoins(reqs);
|
|
2078
2148
|
}
|
|
2079
2149
|
};
|
|
2150
|
+
var MSafeSingleWallet = class {
|
|
2151
|
+
constructor(account) {
|
|
2152
|
+
this.account = account;
|
|
2153
|
+
}
|
|
2154
|
+
async address() {
|
|
2155
|
+
return this.account.address;
|
|
2156
|
+
}
|
|
2157
|
+
};
|
|
2158
|
+
var SingleWalletAdapter = class {
|
|
2159
|
+
constructor(singleWallet, suiClient) {
|
|
2160
|
+
this.singleWallet = singleWallet;
|
|
2161
|
+
this.suiClient = suiClient;
|
|
2162
|
+
}
|
|
2163
|
+
get type() {
|
|
2164
|
+
return "single" /* single */;
|
|
2165
|
+
}
|
|
2166
|
+
async address() {
|
|
2167
|
+
return this.singleWallet.address();
|
|
2168
|
+
}
|
|
2169
|
+
async requestCoins(reqs) {
|
|
2170
|
+
return Promise.all(reqs.map((req) => this.requestCoin(req)));
|
|
2171
|
+
}
|
|
2172
|
+
async requestCoin(req) {
|
|
2173
|
+
if (isSameCoinType(req.coinType, import_utils9.SUI_TYPE_ARG)) {
|
|
2174
|
+
return {
|
|
2175
|
+
primaryCoin: GAS_OBJECT_SPEC
|
|
2176
|
+
};
|
|
2177
|
+
}
|
|
2178
|
+
if (req.amount <= 0) {
|
|
2179
|
+
throw new InvalidInputError("Invalid coin request", "coinAmount", req.amount);
|
|
2180
|
+
}
|
|
2181
|
+
const coins = await getCoinsWithAmount(this.suiClient, await this.address(), req.amount, req.coinType);
|
|
2182
|
+
if (coins.length === 0) {
|
|
2183
|
+
throw new SanityError("no coins available");
|
|
2184
|
+
}
|
|
2185
|
+
return {
|
|
2186
|
+
primaryCoin: coins[0].coinObjectId,
|
|
2187
|
+
mergedCoins: coins.slice(1).map((coin) => coin.coinObjectId)
|
|
2188
|
+
};
|
|
2189
|
+
}
|
|
2190
|
+
};
|
|
2080
2191
|
var MPayClient = class {
|
|
2081
2192
|
globals;
|
|
2082
2193
|
helper;
|
|
@@ -2084,6 +2195,10 @@ var MPayClient = class {
|
|
|
2084
2195
|
this.globals = Globals.new(env, options);
|
|
2085
2196
|
this.helper = new MPayHelper(this.globals);
|
|
2086
2197
|
}
|
|
2198
|
+
connectSingleWallet(wallet) {
|
|
2199
|
+
const adapter = new SingleWalletAdapter(wallet, this.globals.suiClient);
|
|
2200
|
+
this.globals.connectWallet(adapter);
|
|
2201
|
+
}
|
|
2087
2202
|
connectMSafeAccount(msafe) {
|
|
2088
2203
|
const adapter = new MSafeAccountAdapter(msafe);
|
|
2089
2204
|
this.globals.connectWallet(adapter);
|
|
@@ -2140,8 +2255,9 @@ var CreateStreamIntention = class _CreateStreamIntention extends CoreBaseIntenti
|
|
|
2140
2255
|
txType;
|
|
2141
2256
|
txSubType;
|
|
2142
2257
|
async build(input) {
|
|
2143
|
-
const { network } = input;
|
|
2258
|
+
const { network, account } = input;
|
|
2144
2259
|
const mpayClient = new MPayClient(network === "sui:mainnet" ? "prod" /* prod */ : "dev" /* dev */);
|
|
2260
|
+
mpayClient.connectSingleWallet(new MSafeSingleWallet(account));
|
|
2145
2261
|
const txb = await mpayClient.createStream(this.data);
|
|
2146
2262
|
return txb;
|
|
2147
2263
|
}
|
|
@@ -2151,11 +2267,11 @@ var CreateStreamIntention = class _CreateStreamIntention extends CoreBaseIntenti
|
|
|
2151
2267
|
};
|
|
2152
2268
|
|
|
2153
2269
|
// src/apps/mpay/decoder/create.ts
|
|
2154
|
-
var
|
|
2270
|
+
var import_utils12 = require("@mysten/sui.js/utils");
|
|
2155
2271
|
|
|
2156
2272
|
// src/apps/mpay/decoder/moveCall.ts
|
|
2157
2273
|
var import_bcs2 = require("@mysten/sui.js/bcs");
|
|
2158
|
-
var
|
|
2274
|
+
var import_utils11 = require("@mysten/sui.js/utils");
|
|
2159
2275
|
var MoveCallHelper = class _MoveCallHelper {
|
|
2160
2276
|
constructor(moveCall, txb) {
|
|
2161
2277
|
this.moveCall = moveCall;
|
|
@@ -2175,7 +2291,7 @@ var MoveCallHelper = class _MoveCallHelper {
|
|
|
2175
2291
|
}
|
|
2176
2292
|
decodeInputAddress(argIndex) {
|
|
2177
2293
|
const input = this.decodePureArg(argIndex, "address");
|
|
2178
|
-
return (0,
|
|
2294
|
+
return (0, import_utils11.normalizeSuiAddress)(input);
|
|
2179
2295
|
}
|
|
2180
2296
|
decodeInputString(argIndex) {
|
|
2181
2297
|
return this.decodePureArg(argIndex, "string");
|
|
@@ -2212,21 +2328,21 @@ var MoveCallHelper = class _MoveCallHelper {
|
|
|
2212
2328
|
if (!("Object" in input.value) || !("ImmOrOwned" in input.value.Object)) {
|
|
2213
2329
|
throw new Error("not ImmOrOwned");
|
|
2214
2330
|
}
|
|
2215
|
-
return (0,
|
|
2331
|
+
return (0, import_utils11.normalizeSuiAddress)(input.value.Object.ImmOrOwned.objectId);
|
|
2216
2332
|
}
|
|
2217
|
-
return (0,
|
|
2333
|
+
return (0, import_utils11.normalizeSuiAddress)(input.value);
|
|
2218
2334
|
}
|
|
2219
2335
|
static getSharedObjectId(input) {
|
|
2220
2336
|
if (input.type !== "object") {
|
|
2221
2337
|
throw new Error(`not object argument: ${JSON.stringify(input)}`);
|
|
2222
2338
|
}
|
|
2223
2339
|
if (typeof input.value !== "object") {
|
|
2224
|
-
return (0,
|
|
2340
|
+
return (0, import_utils11.normalizeSuiAddress)(input.value);
|
|
2225
2341
|
}
|
|
2226
2342
|
if (!("Object" in input.value) || !("Shared" in input.value.Object)) {
|
|
2227
2343
|
throw new Error("not Shared");
|
|
2228
2344
|
}
|
|
2229
|
-
return (0,
|
|
2345
|
+
return (0, import_utils11.normalizeSuiAddress)(input.value.Object.Shared.objectId);
|
|
2230
2346
|
}
|
|
2231
2347
|
static getPureInput(input, bcsType) {
|
|
2232
2348
|
if (input.type !== "pure") {
|
|
@@ -2242,7 +2358,7 @@ var MoveCallHelper = class _MoveCallHelper {
|
|
|
2242
2358
|
return import_bcs2.bcs.de(bcsType, new Uint8Array(bcsVal));
|
|
2243
2359
|
}
|
|
2244
2360
|
typeArg(index) {
|
|
2245
|
-
return (0,
|
|
2361
|
+
return (0, import_utils11.normalizeStructTag)(this.moveCall.typeArguments[index]);
|
|
2246
2362
|
}
|
|
2247
2363
|
txArg(index) {
|
|
2248
2364
|
return this.moveCall.arguments[index];
|
|
@@ -2344,11 +2460,11 @@ var CreateStreamDecodeHelper = class {
|
|
|
2344
2460
|
const coinType = moveCall.typeArg(0);
|
|
2345
2461
|
const paymentCoin = moveCall.txArg(2);
|
|
2346
2462
|
const paymentCoinMerge = this.getCoinMergeFromNestedResult(paymentCoin, coinType, moveCall);
|
|
2347
|
-
if (coinType === (0,
|
|
2463
|
+
if (coinType === (0, import_utils12.normalizeStructTag)(import_utils12.SUI_TYPE_ARG)) {
|
|
2348
2464
|
return [paymentCoinMerge];
|
|
2349
2465
|
}
|
|
2350
2466
|
const flatFeeCoin = moveCall.txArg(3);
|
|
2351
|
-
const flatCoinMerge = this.getCoinMergeFromNestedResult(flatFeeCoin, (0,
|
|
2467
|
+
const flatCoinMerge = this.getCoinMergeFromNestedResult(flatFeeCoin, (0, import_utils12.normalizeStructTag)(import_utils12.SUI_TYPE_ARG), moveCall);
|
|
2352
2468
|
return [paymentCoinMerge, flatCoinMerge];
|
|
2353
2469
|
}
|
|
2354
2470
|
getCoinMergeFromNestedResult(coinArg, coinType, moveCall) {
|
|
@@ -2712,7 +2828,7 @@ var MSafeApps = class {
|
|
|
2712
2828
|
// src/apps/plain-transaction/helper.ts
|
|
2713
2829
|
var import_sui3_utils6 = require("@msafe/sui3-utils");
|
|
2714
2830
|
var import_transactions9 = require("@mysten/sui.js/transactions");
|
|
2715
|
-
var
|
|
2831
|
+
var import_utils15 = require("@mysten/sui.js/utils");
|
|
2716
2832
|
var import_sort_keys_recursive2 = __toESM(require("sort-keys-recursive"));
|
|
2717
2833
|
var PlainTransactionApplication = "msafe-plain-tx";
|
|
2718
2834
|
var PlainTransactionType = import_sui3_utils6.TransactionSubTypes.others.plain;
|
|
@@ -2727,11 +2843,11 @@ var PlainTransactionHelper = class {
|
|
|
2727
2843
|
return {
|
|
2728
2844
|
txType: import_sui3_utils6.TransactionType.Other,
|
|
2729
2845
|
txSubType: PlainTransactionType,
|
|
2730
|
-
intentionData: { content: (0,
|
|
2846
|
+
intentionData: { content: (0, import_utils15.toHEX)(content) }
|
|
2731
2847
|
};
|
|
2732
2848
|
}
|
|
2733
2849
|
async build(input) {
|
|
2734
|
-
return import_transactions9.TransactionBlock.from((0,
|
|
2850
|
+
return import_transactions9.TransactionBlock.from((0, import_utils15.fromHEX)(input.intentionData.content));
|
|
2735
2851
|
}
|
|
2736
2852
|
};
|
|
2737
2853
|
|