@streamflow/stream 7.5.3 → 8.0.0-alpha.p287.5172056
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/BaseStreamClient-CQOC8m8V.d.cts +542 -0
- package/dist/cjs/aptos/index.cjs +456 -0
- package/dist/cjs/aptos/index.cjs.map +1 -0
- package/dist/cjs/aptos/index.d.cts +14 -0
- package/dist/cjs/evm/index.cjs +1915 -0
- package/dist/cjs/evm/index.cjs.map +1 -0
- package/dist/cjs/evm/index.d.cts +13 -0
- package/dist/cjs/index-CYu6i--S.d.cts +136 -0
- package/dist/cjs/index-DUVcpIhD.d.cts +203 -0
- package/dist/cjs/index-b7Qo5mCj.d.cts +664 -0
- package/dist/cjs/index-fNLnPKzv.d.cts +213 -0
- package/dist/cjs/index.cjs +7189 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +192 -0
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.cjs +4 -0
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.cjs.map +1 -0
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.d.cts +1234 -0
- package/dist/cjs/solana/index.cjs +3749 -0
- package/dist/cjs/solana/index.cjs.map +1 -0
- package/dist/cjs/solana/index.d.cts +17 -0
- package/dist/cjs/sui/index.cjs +1021 -0
- package/dist/cjs/sui/index.cjs.map +1 -0
- package/dist/cjs/sui/index.d.cts +13 -0
- package/dist/esm/BaseStreamClient-CQOC8m8V.d.ts +542 -0
- package/dist/esm/aptos/index.d.ts +14 -4
- package/dist/esm/aptos/index.js +443 -4
- package/dist/esm/aptos/index.js.map +1 -0
- package/dist/esm/evm/index.d.ts +13 -5
- package/dist/esm/evm/index.js +1902 -5
- package/dist/esm/evm/index.js.map +1 -0
- package/dist/esm/index-BEo0O2IG.d.ts +664 -0
- package/dist/esm/index-CWmb3-x9.d.ts +136 -0
- package/dist/esm/index-Cgv37xlG.d.ts +213 -0
- package/dist/esm/index-D6QYg8hn.d.ts +203 -0
- package/dist/esm/index.d.ts +192 -10
- package/dist/esm/index.js +7096 -10
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/solana/descriptor/idl/streamflow_aligned_unlocks.json +917 -1368
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.d.ts +3 -1
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js +3 -1
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js.map +1 -0
- package/dist/esm/solana/index.d.ts +17 -7
- package/dist/esm/solana/index.js +3693 -7
- package/dist/esm/solana/index.js.map +1 -0
- package/dist/esm/sui/index.d.ts +13 -4
- package/dist/esm/sui/index.js +1011 -4
- package/dist/esm/sui/index.js.map +1 -0
- package/package.json +57 -27
- package/dist/cjs/__tests__/aptos/streamClient.spec.js +0 -111
- package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +0 -45
- package/dist/cjs/aptos/StreamClient.js +0 -226
- package/dist/cjs/aptos/constants.js +0 -27
- package/dist/cjs/aptos/index.js +0 -38
- package/dist/cjs/aptos/types.js +0 -69
- package/dist/cjs/aptos/utils.js +0 -34
- package/dist/cjs/aptos/wallet.js +0 -34
- package/dist/cjs/common/BaseStreamClient.js +0 -23
- package/dist/cjs/common/GenericStreamClient.js +0 -102
- package/dist/cjs/common/constants.js +0 -10
- package/dist/cjs/common/contractUtils.js +0 -77
- package/dist/cjs/common/types.js +0 -141
- package/dist/cjs/common/utils.js +0 -69
- package/dist/cjs/evm/StreamClient.js +0 -238
- package/dist/cjs/evm/abi.js +0 -1257
- package/dist/cjs/evm/constants.js +0 -38
- package/dist/cjs/evm/ercAbi.js +0 -224
- package/dist/cjs/evm/index.js +0 -40
- package/dist/cjs/evm/types.js +0 -66
- package/dist/cjs/evm/utils.js +0 -11
- package/dist/cjs/index.js +0 -43
- package/dist/cjs/solana/StreamClient.js +0 -1042
- package/dist/cjs/solana/constants.js +0 -95
- package/dist/cjs/solana/descriptor/idl/streamflow_aligned_unlocks.json +0 -1437
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.js +0 -2
- package/dist/cjs/solana/index.js +0 -40
- package/dist/cjs/solana/instructionTypes.js +0 -2
- package/dist/cjs/solana/instructions.js +0 -298
- package/dist/cjs/solana/layout.js +0 -182
- package/dist/cjs/solana/lib/derive-accounts.js +0 -17
- package/dist/cjs/solana/lib/utils.js +0 -127
- package/dist/cjs/solana/timelockIDL.js +0 -422
- package/dist/cjs/solana/types.js +0 -93
- package/dist/cjs/sui/StreamClient.js +0 -416
- package/dist/cjs/sui/constants.js +0 -42
- package/dist/cjs/sui/index.js +0 -37
- package/dist/cjs/sui/types.js +0 -68
- package/dist/cjs/sui/utils.js +0 -46
- package/dist/cjs/sui/wallet.js +0 -40
- package/dist/esm/__tests__/aptos/streamClient.spec.d.ts +0 -1
- package/dist/esm/__tests__/aptos/streamClient.spec.js +0 -106
- package/dist/esm/__tests__/common/GenericStreamClient.spec.d.ts +0 -1
- package/dist/esm/__tests__/common/GenericStreamClient.spec.js +0 -40
- package/dist/esm/aptos/StreamClient.d.ts +0 -53
- package/dist/esm/aptos/StreamClient.js +0 -226
- package/dist/esm/aptos/constants.d.ts +0 -8
- package/dist/esm/aptos/constants.js +0 -24
- package/dist/esm/aptos/types.d.ts +0 -109
- package/dist/esm/aptos/types.js +0 -105
- package/dist/esm/aptos/utils.d.ts +0 -7
- package/dist/esm/aptos/utils.js +0 -30
- package/dist/esm/aptos/wallet.d.ts +0 -9
- package/dist/esm/aptos/wallet.js +0 -33
- package/dist/esm/common/BaseStreamClient.d.ts +0 -22
- package/dist/esm/common/BaseStreamClient.js +0 -19
- package/dist/esm/common/GenericStreamClient.d.ts +0 -72
- package/dist/esm/common/GenericStreamClient.js +0 -101
- package/dist/esm/common/constants.d.ts +0 -4
- package/dist/esm/common/constants.js +0 -4
- package/dist/esm/common/contractUtils.d.ts +0 -63
- package/dist/esm/common/contractUtils.js +0 -61
- package/dist/esm/common/types.d.ts +0 -353
- package/dist/esm/common/types.js +0 -135
- package/dist/esm/common/utils.d.ts +0 -32
- package/dist/esm/common/utils.js +0 -59
- package/dist/esm/evm/StreamClient.d.ts +0 -32
- package/dist/esm/evm/StreamClient.js +0 -237
- package/dist/esm/evm/abi.d.ts +0 -111
- package/dist/esm/evm/abi.js +0 -1255
- package/dist/esm/evm/constants.d.ts +0 -20
- package/dist/esm/evm/constants.js +0 -35
- package/dist/esm/evm/ercAbi.d.ts +0 -39
- package/dist/esm/evm/ercAbi.js +0 -222
- package/dist/esm/evm/types.d.ts +0 -98
- package/dist/esm/evm/types.js +0 -102
- package/dist/esm/evm/utils.d.ts +0 -1
- package/dist/esm/evm/utils.js +0 -8
- package/dist/esm/solana/StreamClient.d.ts +0 -150
- package/dist/esm/solana/StreamClient.js +0 -1017
- package/dist/esm/solana/constants.d.ts +0 -70
- package/dist/esm/solana/constants.js +0 -92
- package/dist/esm/solana/instructionTypes.d.ts +0 -101
- package/dist/esm/solana/instructionTypes.js +0 -1
- package/dist/esm/solana/instructions.d.ts +0 -142
- package/dist/esm/solana/instructions.js +0 -265
- package/dist/esm/solana/layout.d.ts +0 -27
- package/dist/esm/solana/layout.js +0 -155
- package/dist/esm/solana/lib/derive-accounts.d.ts +0 -4
- package/dist/esm/solana/lib/derive-accounts.js +0 -11
- package/dist/esm/solana/lib/utils.d.ts +0 -22
- package/dist/esm/solana/lib/utils.js +0 -117
- package/dist/esm/solana/timelockIDL.d.ts +0 -22
- package/dist/esm/solana/timelockIDL.js +0 -420
- package/dist/esm/solana/types.d.ts +0 -180
- package/dist/esm/solana/types.js +0 -142
- package/dist/esm/sui/StreamClient.d.ts +0 -82
- package/dist/esm/sui/StreamClient.js +0 -417
- package/dist/esm/sui/constants.d.ts +0 -10
- package/dist/esm/sui/constants.js +0 -39
- package/dist/esm/sui/types.d.ts +0 -167
- package/dist/esm/sui/types.js +0 -104
- package/dist/esm/sui/utils.d.ts +0 -11
- package/dist/esm/sui/utils.js +0 -39
- package/dist/esm/sui/wallet.d.ts +0 -17
- package/dist/esm/sui/wallet.js +0 -38
|
@@ -1,416 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const client_1 = require("@mysten/sui/client");
|
|
4
|
-
const transactions_1 = require("@mysten/sui/transactions");
|
|
5
|
-
const utils_1 = require("@mysten/sui/utils");
|
|
6
|
-
const bcs_1 = require("@mysten/sui/bcs");
|
|
7
|
-
const BaseStreamClient_js_1 = require("../common/BaseStreamClient.js");
|
|
8
|
-
const types_js_1 = require("../common/types.js");
|
|
9
|
-
const constants_js_1 = require("./constants.js");
|
|
10
|
-
const types_js_2 = require("./types.js");
|
|
11
|
-
const utils_js_1 = require("./utils.js");
|
|
12
|
-
const wallet_js_1 = require("./wallet.js");
|
|
13
|
-
const utils_js_2 = require("../common/utils.js");
|
|
14
|
-
const constants_js_2 = require("../common/constants.js");
|
|
15
|
-
class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
16
|
-
constructor(clusterUrl, cluster = types_js_1.ICluster.Mainnet, ids) {
|
|
17
|
-
super();
|
|
18
|
-
this.programId = ids?.program ? ids.program : constants_js_1.SUI_PROGRAM_IDS[cluster];
|
|
19
|
-
this.configId = ids?.config ? ids.config : constants_js_1.SUI_CONFIG_IDS[cluster];
|
|
20
|
-
this.feeTableId = ids?.feeTable ? ids.feeTable : constants_js_1.SUI_FEE_TABLE_IDS[cluster];
|
|
21
|
-
this.client = new client_1.SuiClient({ url: clusterUrl });
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Creates a new stream/vesting contract.
|
|
25
|
-
*/
|
|
26
|
-
async create(streamData, { senderWallet }) {
|
|
27
|
-
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
28
|
-
const totalFee = await this.getTotalFee({
|
|
29
|
-
address: streamData.partner ?? wallet.address,
|
|
30
|
-
});
|
|
31
|
-
const [tx] = await this.generateCreateBlock(wallet.address, {
|
|
32
|
-
...streamData,
|
|
33
|
-
recipients: [{ ...streamData }],
|
|
34
|
-
}, totalFee);
|
|
35
|
-
const { digest, events } = await wallet.signAndExecuteTransaction({
|
|
36
|
-
transaction: tx,
|
|
37
|
-
options: { showEvents: true },
|
|
38
|
-
});
|
|
39
|
-
return {
|
|
40
|
-
ixs: [],
|
|
41
|
-
txId: digest,
|
|
42
|
-
metadataId: events[0].parsedJson.address,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Creates multiple stream/vesting contracts.
|
|
47
|
-
* We don't chain transactions in one Block so that one failed transaction does not revert all others.
|
|
48
|
-
*/
|
|
49
|
-
async createMultiple(multipleStreamData, { senderWallet }) {
|
|
50
|
-
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
51
|
-
const totalFee = await this.getTotalFee({
|
|
52
|
-
address: multipleStreamData.partner ?? wallet.address,
|
|
53
|
-
});
|
|
54
|
-
const [tx, firstIndex] = await this.generateCreateBlock(wallet.address, multipleStreamData, totalFee);
|
|
55
|
-
const txs = [];
|
|
56
|
-
const metadatas = [];
|
|
57
|
-
const metadataToRecipient = {};
|
|
58
|
-
const errors = [];
|
|
59
|
-
try {
|
|
60
|
-
const executedTx = await wallet.signAndExecuteTransaction({
|
|
61
|
-
transaction: tx,
|
|
62
|
-
options: { showEffects: true, showEvents: true },
|
|
63
|
-
});
|
|
64
|
-
const digest = executedTx.digest;
|
|
65
|
-
// effects may be string according to Sui Wallet standard, events won't even be returned
|
|
66
|
-
// https://github.com/MystenLabs/ts-sdks/blob/main/packages/wallet-standard/src/features/suiSignAndExecuteTransaction.ts#L34
|
|
67
|
-
const { events, effects } = !executedTx.effects || typeof executedTx.effects === "string"
|
|
68
|
-
? await (0, utils_js_1.getTransactionBlock)(this.client, { digest, options: { showEvents: true, showEffects: true } })
|
|
69
|
-
: executedTx;
|
|
70
|
-
txs.push(digest);
|
|
71
|
-
if (effects.status.status === "failure") {
|
|
72
|
-
multipleStreamData.recipients.forEach((recipient) => {
|
|
73
|
-
errors.push({
|
|
74
|
-
error: effects.status.error ?? "Unknown error!",
|
|
75
|
-
recipient: recipient.recipient,
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
multipleStreamData.recipients.forEach((recipient, index) => {
|
|
81
|
-
const metadataId = events[index].parsedJson.address;
|
|
82
|
-
metadatas.push(metadataId);
|
|
83
|
-
metadataToRecipient[metadataId] = recipient;
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
catch (e) {
|
|
88
|
-
const errorInfo = (0, utils_js_1.extractSuiErrorInfo)(e.toString() ?? "Unknown error!");
|
|
89
|
-
multipleStreamData.recipients.forEach((recipient, index) => {
|
|
90
|
-
if (errorInfo.index === undefined ||
|
|
91
|
-
errorInfo.index < index + firstIndex ||
|
|
92
|
-
errorInfo.index >= multipleStreamData.recipients.length + firstIndex ||
|
|
93
|
-
errorInfo.index === index + firstIndex) {
|
|
94
|
-
errors.push({
|
|
95
|
-
error: errorInfo.text,
|
|
96
|
-
recipient: recipient.recipient,
|
|
97
|
-
contractErrorCode: errorInfo.parsed?.name,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
return {
|
|
103
|
-
txs,
|
|
104
|
-
metadatas,
|
|
105
|
-
metadataToRecipient,
|
|
106
|
-
errors,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Attempts withdrawing from the specified stream.
|
|
111
|
-
*/
|
|
112
|
-
async withdraw({ id, amount = constants_js_2.WITHDRAW_AVAILABLE_AMOUNT }, { senderWallet, tokenId }) {
|
|
113
|
-
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
114
|
-
const tx = new transactions_1.Transaction();
|
|
115
|
-
tx.moveCall({
|
|
116
|
-
target: `${this.programId}::protocol::withdraw`,
|
|
117
|
-
typeArguments: [tokenId],
|
|
118
|
-
arguments: [
|
|
119
|
-
tx.object(id),
|
|
120
|
-
tx.object(this.configId),
|
|
121
|
-
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
122
|
-
tx.pure.u64(amount.toString()),
|
|
123
|
-
],
|
|
124
|
-
});
|
|
125
|
-
const { digest } = await wallet.signAndExecuteTransaction({
|
|
126
|
-
transaction: tx,
|
|
127
|
-
});
|
|
128
|
-
return {
|
|
129
|
-
ixs: [],
|
|
130
|
-
txId: digest,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Attempts canceling the specified stream.
|
|
135
|
-
*/
|
|
136
|
-
async cancel(cancelData, { senderWallet, tokenId }) {
|
|
137
|
-
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
138
|
-
const tx = new transactions_1.Transaction();
|
|
139
|
-
tx.moveCall({
|
|
140
|
-
target: `${this.programId}::protocol::cancel`,
|
|
141
|
-
typeArguments: [tokenId],
|
|
142
|
-
arguments: [tx.object(cancelData.id), tx.object(this.configId), tx.object(utils_1.SUI_CLOCK_OBJECT_ID)],
|
|
143
|
-
});
|
|
144
|
-
const { digest } = await wallet.signAndExecuteTransaction({
|
|
145
|
-
transaction: tx,
|
|
146
|
-
});
|
|
147
|
-
return {
|
|
148
|
-
ixs: [],
|
|
149
|
-
txId: digest,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
154
|
-
*/
|
|
155
|
-
async transfer(transferData, { senderWallet, tokenId }) {
|
|
156
|
-
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
157
|
-
const tx = new transactions_1.Transaction();
|
|
158
|
-
tx.moveCall({
|
|
159
|
-
target: `${this.programId}::protocol::transfer`,
|
|
160
|
-
typeArguments: [tokenId],
|
|
161
|
-
arguments: [tx.object(transferData.id), tx.pure.address(transferData.newRecipient)],
|
|
162
|
-
});
|
|
163
|
-
const { digest } = await wallet.signAndExecuteTransaction({
|
|
164
|
-
transaction: tx,
|
|
165
|
-
});
|
|
166
|
-
return {
|
|
167
|
-
ixs: [],
|
|
168
|
-
txId: digest,
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Tops up stream account with specified amount.
|
|
173
|
-
*/
|
|
174
|
-
async topup(topupData, { senderWallet, tokenId }) {
|
|
175
|
-
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
176
|
-
const tx = new transactions_1.Transaction();
|
|
177
|
-
const coins = await this.getAllCoins(wallet.address, tokenId);
|
|
178
|
-
const stream = await this.getOne({ id: topupData.id });
|
|
179
|
-
const totalFee = (stream.partnerFeePercent + stream.streamflowFeePercent) / 100;
|
|
180
|
-
const coinObject = this.splitCoinObjectForAmount(tx, topupData.amount, tokenId, coins, totalFee);
|
|
181
|
-
tx.moveCall({
|
|
182
|
-
target: `${this.programId}::protocol::topup`,
|
|
183
|
-
typeArguments: [tokenId],
|
|
184
|
-
arguments: [
|
|
185
|
-
tx.object(topupData.id),
|
|
186
|
-
tx.object(this.configId),
|
|
187
|
-
coinObject,
|
|
188
|
-
tx.gas,
|
|
189
|
-
tx.pure.u64(topupData.amount.toString()),
|
|
190
|
-
],
|
|
191
|
-
});
|
|
192
|
-
this.returnSplittedCoinObject(tx, tokenId, coins, coinObject);
|
|
193
|
-
const { digest } = await wallet.signAndExecuteTransaction({
|
|
194
|
-
transaction: tx,
|
|
195
|
-
});
|
|
196
|
-
return {
|
|
197
|
-
ixs: [],
|
|
198
|
-
txId: digest,
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Fetch stream data by its id (address).
|
|
203
|
-
*/
|
|
204
|
-
async getOne({ id }) {
|
|
205
|
-
const response = await this.client.getObject({
|
|
206
|
-
id,
|
|
207
|
-
options: {
|
|
208
|
-
showContent: true,
|
|
209
|
-
},
|
|
210
|
-
});
|
|
211
|
-
if (!response.data) {
|
|
212
|
-
throw new Error(`Contract with id ${id} could not be found!`);
|
|
213
|
-
}
|
|
214
|
-
const content = response.data.content;
|
|
215
|
-
if (content.dataType !== "moveObject") {
|
|
216
|
-
throw new Error(`Not a Move Object!`);
|
|
217
|
-
}
|
|
218
|
-
return new types_js_2.Contract(content.fields, "0x97e9a9fb1392e9785319f5512d0bfde6ecf7757b09c6de41cec89e798dd361f2::strmt::STRMT");
|
|
219
|
-
}
|
|
220
|
-
async get() {
|
|
221
|
-
throw new Error("Get all method is not supported for Sui chain!");
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Attempts updating the stream auto withdrawal params and amount per period
|
|
225
|
-
*/
|
|
226
|
-
async update(updateData, { senderWallet, tokenId }) {
|
|
227
|
-
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
228
|
-
const tx = new transactions_1.Transaction();
|
|
229
|
-
tx.moveCall({
|
|
230
|
-
target: `${this.programId}::protocol::update`,
|
|
231
|
-
typeArguments: [tokenId],
|
|
232
|
-
arguments: [
|
|
233
|
-
tx.object(updateData.id),
|
|
234
|
-
tx.object(this.configId),
|
|
235
|
-
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
236
|
-
tx.gas,
|
|
237
|
-
bcs_1.bcs
|
|
238
|
-
.vector(bcs_1.bcs.bool())
|
|
239
|
-
.serialize(updateData.enableAutomaticWithdrawal !== undefined ? [updateData.enableAutomaticWithdrawal] : []),
|
|
240
|
-
bcs_1.bcs
|
|
241
|
-
.vector(bcs_1.bcs.u64())
|
|
242
|
-
.serialize(updateData.withdrawFrequency !== undefined ? [updateData.withdrawFrequency.toString()] : []),
|
|
243
|
-
bcs_1.bcs
|
|
244
|
-
.vector(bcs_1.bcs.u64())
|
|
245
|
-
.serialize(updateData.amountPerPeriod !== undefined ? [updateData.amountPerPeriod.toString()] : []),
|
|
246
|
-
],
|
|
247
|
-
});
|
|
248
|
-
const { digest } = await wallet.signAndExecuteTransaction({
|
|
249
|
-
transaction: tx,
|
|
250
|
-
});
|
|
251
|
-
return {
|
|
252
|
-
ixs: [],
|
|
253
|
-
txId: digest,
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
extractErrorCode(err) {
|
|
257
|
-
const errorInfo = (0, utils_js_1.extractSuiErrorInfo)(err.toString() ?? "Unknown error!");
|
|
258
|
-
return errorInfo?.parsed?.name || null;
|
|
259
|
-
}
|
|
260
|
-
async getFees({ address }) {
|
|
261
|
-
const response = await this.client.getObject({
|
|
262
|
-
id: this.feeTableId,
|
|
263
|
-
options: {
|
|
264
|
-
showContent: true,
|
|
265
|
-
},
|
|
266
|
-
});
|
|
267
|
-
const content = response.data.content;
|
|
268
|
-
if (content.dataType !== "moveObject") {
|
|
269
|
-
throw new Error(`Not a Move Object!`);
|
|
270
|
-
}
|
|
271
|
-
const fields = content.fields;
|
|
272
|
-
const fieldsResponse = await this.client.getDynamicFields({
|
|
273
|
-
parentId: fields.values.fields.id.id,
|
|
274
|
-
});
|
|
275
|
-
const partnerDynamicField = fieldsResponse.data.filter((item) => item.name.value === address)[0];
|
|
276
|
-
if (!partnerDynamicField) {
|
|
277
|
-
return null;
|
|
278
|
-
}
|
|
279
|
-
const valueResponse = await this.client.getObject({
|
|
280
|
-
id: partnerDynamicField.objectId,
|
|
281
|
-
options: {
|
|
282
|
-
showContent: true,
|
|
283
|
-
},
|
|
284
|
-
});
|
|
285
|
-
const valueContent = valueResponse.data.content;
|
|
286
|
-
if (valueContent.dataType !== "moveObject") {
|
|
287
|
-
throw new Error(`Not a Move Object!`);
|
|
288
|
-
}
|
|
289
|
-
const valueFields = valueContent.fields.value.fields;
|
|
290
|
-
return {
|
|
291
|
-
streamflowFee: Number(valueFields.streamflow_fee) / 100,
|
|
292
|
-
partnerFee: Number(valueFields.partner_fee) / 100,
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
async getDefaultStreamflowFee() {
|
|
296
|
-
const response = await this.client.getObject({
|
|
297
|
-
id: this.configId,
|
|
298
|
-
options: {
|
|
299
|
-
showContent: true,
|
|
300
|
-
},
|
|
301
|
-
});
|
|
302
|
-
const content = response.data.content;
|
|
303
|
-
if (content.dataType !== "moveObject") {
|
|
304
|
-
throw new Error(`Not a Move Object!`);
|
|
305
|
-
}
|
|
306
|
-
const fields = content.fields;
|
|
307
|
-
return Number(fields.streamflow_fee) / 100;
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Returns StreamClient protocol program ID.
|
|
311
|
-
*/
|
|
312
|
-
getProgramId() {
|
|
313
|
-
return this.programId;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Utility function to generate Transaction Block to create streams
|
|
317
|
-
*/
|
|
318
|
-
async generateCreateBlock(walletAddress, multipleStreamData, totalFee) {
|
|
319
|
-
let coins = await this.getAllCoins(walletAddress, multipleStreamData.tokenId);
|
|
320
|
-
const totalAmount = multipleStreamData.recipients
|
|
321
|
-
.map((recipiient) => recipiient.amount)
|
|
322
|
-
.reduce((prev, current) => current.add(prev));
|
|
323
|
-
const tx = new transactions_1.Transaction();
|
|
324
|
-
const coinObject = this.splitCoinObjectForAmount(tx, totalAmount, multipleStreamData.tokenId, coins, totalFee);
|
|
325
|
-
coins = [coins[0]];
|
|
326
|
-
let firstIndex = null;
|
|
327
|
-
multipleStreamData.recipients.forEach((recipient) => {
|
|
328
|
-
const result = tx.moveCall({
|
|
329
|
-
target: `${this.programId}::protocol::create`,
|
|
330
|
-
typeArguments: [multipleStreamData.tokenId],
|
|
331
|
-
arguments: [
|
|
332
|
-
tx.object(this.configId),
|
|
333
|
-
tx.object(this.feeTableId),
|
|
334
|
-
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
335
|
-
coinObject,
|
|
336
|
-
tx.gas,
|
|
337
|
-
tx.pure.u64(recipient.amount.toString()),
|
|
338
|
-
tx.pure.u64(multipleStreamData.period),
|
|
339
|
-
tx.pure.u64(recipient.amountPerPeriod.toString()),
|
|
340
|
-
tx.pure.u64(multipleStreamData.start),
|
|
341
|
-
tx.pure.u64(recipient.cliffAmount.toString()),
|
|
342
|
-
tx.pure.bool(multipleStreamData.cancelableBySender),
|
|
343
|
-
tx.pure.bool(multipleStreamData.cancelableByRecipient),
|
|
344
|
-
tx.pure.bool(multipleStreamData.transferableBySender),
|
|
345
|
-
tx.pure.bool(multipleStreamData.transferableByRecipient),
|
|
346
|
-
tx.pure.bool(multipleStreamData.canTopup),
|
|
347
|
-
tx.pure.bool(!!multipleStreamData.canPause),
|
|
348
|
-
tx.pure.bool(!!multipleStreamData.canUpdateRate),
|
|
349
|
-
tx.pure.bool(!!multipleStreamData.automaticWithdrawal),
|
|
350
|
-
tx.pure.u64(multipleStreamData.withdrawalFrequency || 0),
|
|
351
|
-
tx.pure.string(recipient.name),
|
|
352
|
-
tx.pure.address(recipient.recipient),
|
|
353
|
-
tx.pure.address(multipleStreamData.partner || walletAddress),
|
|
354
|
-
],
|
|
355
|
-
});
|
|
356
|
-
if (result.$kind === "Result" && firstIndex === null) {
|
|
357
|
-
firstIndex = result.Result;
|
|
358
|
-
}
|
|
359
|
-
});
|
|
360
|
-
this.returnSplittedCoinObject(tx, multipleStreamData.tokenId, coins, coinObject);
|
|
361
|
-
return [tx, firstIndex];
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Returns all coins owned by a Wallet
|
|
365
|
-
* @param walletAddress wallet address
|
|
366
|
-
* @param coinType coin type
|
|
367
|
-
* @returns Array of Coin Structs
|
|
368
|
-
*/
|
|
369
|
-
async getAllCoins(walletAddress, coinType) {
|
|
370
|
-
let coinsResponse = await this.client.getCoins({
|
|
371
|
-
owner: walletAddress,
|
|
372
|
-
coinType: coinType,
|
|
373
|
-
});
|
|
374
|
-
const coins = coinsResponse.data;
|
|
375
|
-
while (coinsResponse.hasNextPage) {
|
|
376
|
-
coinsResponse = await this.client.getCoins({
|
|
377
|
-
owner: walletAddress,
|
|
378
|
-
coinType: coinType,
|
|
379
|
-
cursor: coinsResponse.nextCursor,
|
|
380
|
-
});
|
|
381
|
-
coins.push(...coinsResponse.data);
|
|
382
|
-
}
|
|
383
|
-
return coins;
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Utility function to split Coin object and use splitted object for stream operations.
|
|
387
|
-
* We do it like thid to mitigate risk of Transaction reverting in case Stream is created for Sui Coin object.
|
|
388
|
-
* This way we can safely pass splitted Sui Coin object in Stream payload and use another object for gas/withdrawal fees.
|
|
389
|
-
* @param tx current transanction block
|
|
390
|
-
* @param amount minimal amount of coins requried
|
|
391
|
-
* @param coinType coin type
|
|
392
|
-
* @param coins array of owned coins of the same type
|
|
393
|
-
* @param totalFee partner and treasury fees
|
|
394
|
-
* @returns Coin Object to use in a Move Call
|
|
395
|
-
*/
|
|
396
|
-
splitCoinObjectForAmount(tx, amount, coinType, coins, totalFee) {
|
|
397
|
-
const coinObject = coinType === utils_1.SUI_TYPE_ARG ? tx.gas : tx.object(coins[0].coinObjectId);
|
|
398
|
-
if (coins.length > 1) {
|
|
399
|
-
tx.mergeCoins(coinObject, coins.slice(1).map((item) => tx.object(item.coinObjectId)));
|
|
400
|
-
}
|
|
401
|
-
const totalAmount = (0, utils_js_2.calculateTotalAmountToDeposit)(amount, totalFee);
|
|
402
|
-
return tx.splitCoins(coinObject, [tx.pure.u64(totalAmount.toString())])[0];
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* Return previously splitted Coin Object to owner and merge it to to rebate storage fees
|
|
406
|
-
* @param tx current transaction
|
|
407
|
-
* @param coinType coin type
|
|
408
|
-
* @param coinObject splitted object
|
|
409
|
-
* @param coins array of objects used in
|
|
410
|
-
*/
|
|
411
|
-
returnSplittedCoinObject(tx, coinType, coins, coinObject) {
|
|
412
|
-
const firstCoinObject = coinType === utils_1.SUI_TYPE_ARG ? tx.gas : tx.object(coins[0].coinObjectId);
|
|
413
|
-
tx.mergeCoins(firstCoinObject, [coinObject]);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
exports.default = SuiStreamClient;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SUI_MODULE_ERROR_MAP = exports.SUI_ERROR_MATCH_REGEX = exports.SUI_FEE_TABLE_IDS = exports.SUI_CONFIG_IDS = exports.SUI_PROGRAM_IDS = void 0;
|
|
4
|
-
const types_js_1 = require("../common/types.js");
|
|
5
|
-
// TODO: remove Devnet and Local addresses as they are not deployed, they are just a copy Testnet values
|
|
6
|
-
exports.SUI_PROGRAM_IDS = {
|
|
7
|
-
[types_js_1.ICluster.Mainnet]: "0xe456a3a1d4e58e85b4b7175fabe6dae895b983f1379bb8948d6ec2f137b08a7b",
|
|
8
|
-
[types_js_1.ICluster.Devnet]: "0x34dacd839e1758ebb70bdcd4e08f18fbfef5e2b96d9aa7ce2b4a71d96ca0df5a",
|
|
9
|
-
[types_js_1.ICluster.Testnet]: "0x34dacd839e1758ebb70bdcd4e08f18fbfef5e2b96d9aa7ce2b4a71d96ca0df5a",
|
|
10
|
-
[types_js_1.ICluster.Local]: "0x34dacd839e1758ebb70bdcd4e08f18fbfef5e2b96d9aa7ce2b4a71d96ca0df5a",
|
|
11
|
-
};
|
|
12
|
-
exports.SUI_CONFIG_IDS = {
|
|
13
|
-
[types_js_1.ICluster.Mainnet]: "0x6cf6760b64245b8d23ef57c28ddceb6adbd540a23a509fef29b82237da4ab87b",
|
|
14
|
-
[types_js_1.ICluster.Devnet]: "0xd6c9f5074584f58074ce56e3c5cc436d82258ec3285f186a0d6438a60bacdbf8",
|
|
15
|
-
[types_js_1.ICluster.Testnet]: "0xd6c9f5074584f58074ce56e3c5cc436d82258ec3285f186a0d6438a60bacdbf8",
|
|
16
|
-
[types_js_1.ICluster.Local]: "0xd6c9f5074584f58074ce56e3c5cc436d82258ec3285f186a0d6438a60bacdbf8",
|
|
17
|
-
};
|
|
18
|
-
exports.SUI_FEE_TABLE_IDS = {
|
|
19
|
-
[types_js_1.ICluster.Mainnet]: "0xad9b75399632583fb9fcae6b5bcca34e6542ab3bedb630ecbd3f15cb1cc48dbe",
|
|
20
|
-
[types_js_1.ICluster.Devnet]: "0x6057b093904c5bdfec1067d2b8a4dc35f65bcab03b3029ad716c4882b0f36078",
|
|
21
|
-
[types_js_1.ICluster.Testnet]: "0x6057b093904c5bdfec1067d2b8a4dc35f65bcab03b3029ad716c4882b0f36078",
|
|
22
|
-
[types_js_1.ICluster.Local]: "0x6057b093904c5bdfec1067d2b8a4dc35f65bcab03b3029ad716c4882b0f36078",
|
|
23
|
-
};
|
|
24
|
-
exports.SUI_ERROR_MATCH_REGEX = /MoveAbort\(MoveLocation \{ module: ModuleId \{ address: (\w+), name: Identifier\("([\w_]+)"\) }, function: \d+, instruction: \d+, function_name: Some\("([\w_]+)"\) }, (\d+)\) in command (\d+)/;
|
|
25
|
-
exports.SUI_MODULE_ERROR_MAP = {
|
|
26
|
-
protocol: {
|
|
27
|
-
1: types_js_1.ContractErrorCode.ECONTRACT_NOT_INIT,
|
|
28
|
-
2: types_js_1.ContractErrorCode.EBAD_AMOUNT,
|
|
29
|
-
3: types_js_1.ContractErrorCode.ENO_PERMISSIONS,
|
|
30
|
-
4: types_js_1.ContractErrorCode.EBADINPUT,
|
|
31
|
-
5: types_js_1.ContractErrorCode.ECLOSED,
|
|
32
|
-
6: types_js_1.ContractErrorCode.EBAD_INPUT_AMOUNT_PER_PERIOD,
|
|
33
|
-
8: types_js_1.ContractErrorCode.EBAD_INPUT_UPDATE_RATE,
|
|
34
|
-
9: types_js_1.ContractErrorCode.EBAD_INPUT_CLIFF_AMOUNT,
|
|
35
|
-
10: types_js_1.ContractErrorCode.EBAD_INPUT_PERIOD,
|
|
36
|
-
11: types_js_1.ContractErrorCode.EBAD_INPUT_START,
|
|
37
|
-
13: types_js_1.ContractErrorCode.EBAD_INSUFFICIENT_WITHDRAWAL_FEES,
|
|
38
|
-
14: types_js_1.ContractErrorCode.EBAD_INSUFFICIENT_AMOUNT,
|
|
39
|
-
15: types_js_1.ContractErrorCode.EPAUSED,
|
|
40
|
-
16: types_js_1.ContractErrorCode.ENOTPAUSED,
|
|
41
|
-
},
|
|
42
|
-
};
|
package/dist/cjs/sui/index.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
-
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod;
|
|
23
|
-
var result = {};
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
-
__setModuleDefault(result, mod);
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
-
};
|
|
31
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.constants = exports.SuiStreamClient = void 0;
|
|
33
|
-
var StreamClient_js_1 = require("./StreamClient.js");
|
|
34
|
-
Object.defineProperty(exports, "SuiStreamClient", { enumerable: true, get: function () { return __importDefault(StreamClient_js_1).default; } });
|
|
35
|
-
__exportStar(require("./utils.js"), exports);
|
|
36
|
-
__exportStar(require("./types.js"), exports);
|
|
37
|
-
exports.constants = __importStar(require("./constants.js"));
|
package/dist/cjs/sui/types.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Contract = void 0;
|
|
7
|
-
const bn_js_1 = __importDefault(require("bn.js"));
|
|
8
|
-
const contractUtils_js_1 = require("../common/contractUtils.js");
|
|
9
|
-
const utils_js_1 = require("../common/utils.js");
|
|
10
|
-
class Contract {
|
|
11
|
-
constructor(stream, tokenId) {
|
|
12
|
-
const meta = stream.meta.fields;
|
|
13
|
-
const fees = stream.fees.fields;
|
|
14
|
-
this.magic = 0;
|
|
15
|
-
this.version = parseInt(stream.version);
|
|
16
|
-
this.createdAt = parseInt(stream.created);
|
|
17
|
-
this.withdrawnAmount = new bn_js_1.default(stream.withdrawn);
|
|
18
|
-
this.canceledAt = parseInt(stream.canceled_at);
|
|
19
|
-
this.end = parseInt(stream.end);
|
|
20
|
-
this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at);
|
|
21
|
-
this.sender = stream.sender;
|
|
22
|
-
this.senderTokens = stream.sender;
|
|
23
|
-
this.recipient = stream.recipient;
|
|
24
|
-
this.recipientTokens = stream.recipient;
|
|
25
|
-
this.mint = tokenId;
|
|
26
|
-
this.escrowTokens = "";
|
|
27
|
-
this.streamflowTreasury = "";
|
|
28
|
-
this.streamflowTreasuryTokens = "";
|
|
29
|
-
this.streamflowFeeTotal = new bn_js_1.default(0);
|
|
30
|
-
this.streamflowFeeWithdrawn = new bn_js_1.default(0);
|
|
31
|
-
this.streamflowFeePercent = parseInt(fees.streamflow_fee_percentage) / 10000;
|
|
32
|
-
this.partnerFeeTotal = new bn_js_1.default(0);
|
|
33
|
-
this.partnerFeeWithdrawn = new bn_js_1.default(0);
|
|
34
|
-
this.partnerFeePercent = parseInt(fees.partner_fee_percentage) / 10000;
|
|
35
|
-
this.partner = stream.partner;
|
|
36
|
-
this.partnerTokens = "";
|
|
37
|
-
this.start = parseInt(stream.start);
|
|
38
|
-
this.depositedAmount = new bn_js_1.default(stream.amount);
|
|
39
|
-
this.period = parseInt(stream.period);
|
|
40
|
-
this.amountPerPeriod = new bn_js_1.default(stream.amount_per_period);
|
|
41
|
-
this.cliff = parseInt(stream.start);
|
|
42
|
-
this.cliffAmount = new bn_js_1.default(stream.cliff_amount);
|
|
43
|
-
this.cancelableBySender = meta.cancelable_by_sender;
|
|
44
|
-
this.cancelableByRecipient = meta.cancelable_by_recipient;
|
|
45
|
-
this.automaticWithdrawal = meta.automatic_withdrawal;
|
|
46
|
-
this.transferableBySender = meta.transferable_by_sender;
|
|
47
|
-
this.transferableByRecipient = meta.transferable_by_recipient;
|
|
48
|
-
this.canTopup = meta.can_topup;
|
|
49
|
-
this.name = String.fromCharCode(...meta.contract_name);
|
|
50
|
-
this.withdrawalFrequency = parseInt(meta.withdrawal_frequency);
|
|
51
|
-
this.closed = stream.closed;
|
|
52
|
-
this.currentPauseStart = parseInt(stream.current_pause_start);
|
|
53
|
-
this.pauseCumulative = new bn_js_1.default(stream.pause_cumulative);
|
|
54
|
-
this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
|
|
55
|
-
this.fundsUnlockedAtLastRateChange = new bn_js_1.default(stream.funds_unlocked_at_last_rate_change);
|
|
56
|
-
this.type = (0, contractUtils_js_1.buildStreamType)(this);
|
|
57
|
-
}
|
|
58
|
-
unlocked(currentTimestamp) {
|
|
59
|
-
return (0, contractUtils_js_1.calculateUnlockedAmount)({
|
|
60
|
-
...this,
|
|
61
|
-
currentTimestamp,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
remaining(decimals) {
|
|
65
|
-
return (0, utils_js_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.Contract = Contract;
|
package/dist/cjs/sui/utils.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.extractSuiErrorInfo = extractSuiErrorInfo;
|
|
7
|
-
exports.getTransactionBlock = getTransactionBlock;
|
|
8
|
-
const p_retry_1 = __importDefault(require("p-retry"));
|
|
9
|
-
const constants_js_1 = require("./constants.js");
|
|
10
|
-
function extractSuiErrorInfo(errorText) {
|
|
11
|
-
const error = { text: errorText };
|
|
12
|
-
const match = constants_js_1.SUI_ERROR_MATCH_REGEX.exec(errorText);
|
|
13
|
-
if (!match) {
|
|
14
|
-
return error;
|
|
15
|
-
}
|
|
16
|
-
const moduleName = match[2];
|
|
17
|
-
const errorCode = Number(match[4]);
|
|
18
|
-
const errorName = constants_js_1.SUI_MODULE_ERROR_MAP[moduleName] ? constants_js_1.SUI_MODULE_ERROR_MAP[moduleName][errorCode] : undefined;
|
|
19
|
-
const index = Number(match[5]);
|
|
20
|
-
if (index) {
|
|
21
|
-
error.index = index;
|
|
22
|
-
}
|
|
23
|
-
if (errorName) {
|
|
24
|
-
error.parsed = {
|
|
25
|
-
module: moduleName,
|
|
26
|
-
code: errorCode,
|
|
27
|
-
name: errorName,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
return error;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Fetches transaction block with a retry:
|
|
34
|
-
* retries `Could not find the referenced transaction` error as it could be that some validators still don't have the tx;
|
|
35
|
-
*
|
|
36
|
-
* @param client sui client to use
|
|
37
|
-
* @param input transaction fetch payload,
|
|
38
|
-
*/
|
|
39
|
-
function getTransactionBlock(client, input) {
|
|
40
|
-
return (0, p_retry_1.default)(() => client.getTransactionBlock(input), {
|
|
41
|
-
retries: 5,
|
|
42
|
-
shouldRetry: (error) => error.message.includes("Could not find the referenced transaction"),
|
|
43
|
-
minTimeout: 500,
|
|
44
|
-
maxTimeout: 1000,
|
|
45
|
-
});
|
|
46
|
-
}
|
package/dist/cjs/sui/wallet.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SuiWalletWrapper = void 0;
|
|
4
|
-
exports.isSignerKeypair = isSignerKeypair;
|
|
5
|
-
const cryptography_1 = require("@mysten/sui/cryptography");
|
|
6
|
-
/**
|
|
7
|
-
* Utility function to check if the transaction initiator is a Wallet object
|
|
8
|
-
* @param {Keypair | WalletContextState} walletOrKeypair - Wallet or Keypair in question
|
|
9
|
-
* @return {boolean} - Returns true if parameter is a Wallet.
|
|
10
|
-
*/
|
|
11
|
-
function isSignerKeypair(walletOrKeypair) {
|
|
12
|
-
return (walletOrKeypair instanceof cryptography_1.Keypair ||
|
|
13
|
-
walletOrKeypair.constructor === cryptography_1.Keypair ||
|
|
14
|
-
walletOrKeypair.constructor.name === cryptography_1.Keypair.prototype.constructor.name ||
|
|
15
|
-
"getSecretKey" in walletOrKeypair);
|
|
16
|
-
}
|
|
17
|
-
class SuiWalletWrapper {
|
|
18
|
-
constructor(wallet, client) {
|
|
19
|
-
this.client = client;
|
|
20
|
-
this.wallet = wallet;
|
|
21
|
-
if (isSignerKeypair(wallet)) {
|
|
22
|
-
this.address = wallet.toSuiAddress();
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
this.address = wallet.address;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
async signAndExecuteTransaction(input) {
|
|
29
|
-
if (isSignerKeypair(this.wallet)) {
|
|
30
|
-
return this.client.signAndExecuteTransaction({
|
|
31
|
-
...input,
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
signer: this.wallet,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
return this.wallet.signAndExecuteTransaction(input);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.SuiWalletWrapper = SuiWalletWrapper;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|