@streamflow/stream 6.5.0 → 7.0.0-alpha.10
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/README.md +17 -22
- package/dist/cjs/__tests__/aptos/streamClient.spec.js +111 -0
- package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +45 -0
- package/dist/cjs/aptos/StreamClient.js +226 -0
- package/dist/cjs/aptos/constants.js +27 -0
- package/dist/{aptos → cjs/aptos}/index.js +6 -6
- package/dist/cjs/aptos/types.js +69 -0
- package/dist/{aptos → cjs/aptos}/utils.js +4 -4
- package/dist/cjs/aptos/wallet.js +34 -0
- package/dist/cjs/common/BaseStreamClient.js +23 -0
- package/dist/cjs/common/GenericStreamClient.js +102 -0
- package/dist/{common → cjs/common}/constants.js +2 -2
- package/dist/{common → cjs/common}/contractUtils.js +19 -20
- package/dist/cjs/common/utils.js +66 -0
- package/dist/cjs/evm/StreamClient.js +238 -0
- package/dist/cjs/evm/constants.js +38 -0
- package/dist/{evm → cjs/evm}/index.js +8 -8
- package/dist/{evm → cjs/evm}/types.js +26 -35
- package/dist/{evm → cjs/evm}/utils.js +2 -2
- package/dist/{index.js → cjs/index.js} +10 -10
- package/dist/cjs/solana/StreamClient.js +737 -0
- package/dist/{solana → cjs/solana}/constants.js +33 -33
- package/dist/cjs/solana/index.js +39 -0
- package/dist/{solana → cjs/solana}/instructions.js +83 -83
- package/dist/{solana → cjs/solana}/layout.js +8 -9
- package/dist/{solana → cjs/solana}/types.js +16 -26
- package/dist/cjs/solana/utils.js +134 -0
- package/dist/cjs/sui/StreamClient.js +402 -0
- package/dist/cjs/sui/constants.js +42 -0
- package/dist/{sui → cjs/sui}/index.js +5 -5
- package/dist/cjs/sui/types.js +68 -0
- package/dist/{sui → cjs/sui}/utils.js +7 -7
- package/dist/cjs/sui/wallet.js +40 -0
- package/dist/esm/__tests__/aptos/streamClient.spec.js +106 -0
- package/dist/esm/__tests__/common/GenericStreamClient.spec.js +40 -0
- package/dist/{aptos → esm/aptos}/StreamClient.d.ts +3 -3
- package/dist/esm/aptos/StreamClient.js +226 -0
- package/dist/{aptos → esm/aptos}/constants.d.ts +1 -1
- package/dist/esm/aptos/constants.js +24 -0
- package/dist/esm/aptos/index.d.ts +4 -0
- package/dist/esm/aptos/index.js +4 -0
- package/dist/{aptos → esm/aptos}/types.d.ts +13 -13
- package/dist/esm/aptos/types.js +105 -0
- package/dist/esm/aptos/utils.js +30 -0
- package/dist/esm/aptos/wallet.js +33 -0
- package/dist/{common → esm/common}/BaseStreamClient.d.ts +1 -1
- package/dist/esm/common/BaseStreamClient.js +19 -0
- package/dist/{common → esm/common}/GenericStreamClient.d.ts +6 -6
- package/dist/esm/common/GenericStreamClient.js +101 -0
- package/dist/esm/common/constants.d.ts +3 -0
- package/dist/esm/common/constants.js +3 -0
- package/dist/{common → esm/common}/contractUtils.d.ts +15 -15
- package/dist/esm/common/contractUtils.js +42 -0
- package/dist/{common → esm/common}/types.d.ts +19 -19
- package/dist/esm/common/types.js +106 -0
- package/dist/{common → esm/common}/utils.d.ts +11 -12
- package/dist/esm/common/utils.js +56 -0
- package/dist/{evm → esm/evm}/StreamClient.d.ts +4 -4
- package/dist/esm/evm/StreamClient.js +237 -0
- package/dist/esm/evm/abi.js +1255 -0
- package/dist/{evm → esm/evm}/constants.d.ts +1 -1
- package/dist/esm/evm/constants.js +35 -0
- package/dist/esm/evm/ercAbi.js +222 -0
- package/dist/esm/evm/index.d.ts +5 -0
- package/dist/esm/evm/index.js +5 -0
- package/dist/{evm → esm/evm}/types.d.ts +38 -38
- package/dist/esm/evm/types.js +102 -0
- package/dist/esm/evm/utils.js +8 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +9 -0
- package/dist/{solana → esm/solana}/StreamClient.d.ts +4 -4
- package/dist/esm/solana/StreamClient.js +711 -0
- package/dist/{solana → esm/solana}/constants.d.ts +3 -1
- package/dist/esm/solana/constants.js +62 -0
- package/dist/esm/solana/index.d.ts +6 -0
- package/dist/esm/solana/index.js +6 -0
- package/dist/esm/solana/instructionTypes.js +1 -0
- package/dist/{solana → esm/solana}/instructions.d.ts +18 -18
- package/dist/esm/solana/instructions.js +257 -0
- package/dist/{solana → esm/solana}/layout.d.ts +2 -1
- package/dist/esm/solana/layout.js +155 -0
- package/dist/esm/solana/timelockIDL.js +420 -0
- package/dist/{solana → esm/solana}/types.d.ts +38 -37
- package/dist/esm/solana/types.js +101 -0
- package/dist/{solana → esm/solana}/utils.d.ts +4 -1
- package/dist/esm/solana/utils.js +123 -0
- package/dist/{sui → esm/sui}/StreamClient.d.ts +3 -3
- package/dist/esm/sui/StreamClient.js +403 -0
- package/dist/{sui → esm/sui}/constants.d.ts +1 -1
- package/dist/esm/sui/constants.js +39 -0
- package/dist/esm/sui/index.d.ts +4 -0
- package/dist/esm/sui/index.js +4 -0
- package/dist/{sui → esm/sui}/types.d.ts +13 -13
- package/dist/esm/sui/types.js +104 -0
- package/dist/{sui → esm/sui}/utils.d.ts +1 -1
- package/dist/esm/sui/utils.js +23 -0
- package/dist/{sui → esm/sui}/wallet.d.ts +1 -1
- package/dist/esm/sui/wallet.js +38 -0
- package/package.json +37 -35
- package/dist/__tests__/aptos/streamClient.spec.js +0 -161
- package/dist/__tests__/common/GenericStreamClient.spec.js +0 -44
- package/dist/aptos/StreamClient.js +0 -431
- package/dist/aptos/constants.js +0 -28
- package/dist/aptos/index.d.ts +0 -4
- package/dist/aptos/types.js +0 -77
- package/dist/aptos/wallet.js +0 -89
- package/dist/common/BaseStreamClient.js +0 -71
- package/dist/common/GenericStreamClient.js +0 -128
- package/dist/common/constants.d.ts +0 -3
- package/dist/common/utils.js +0 -118
- package/dist/evm/StreamClient.js +0 -496
- package/dist/evm/constants.js +0 -39
- package/dist/evm/index.d.ts +0 -5
- package/dist/index.d.ts +0 -9
- package/dist/solana/StreamClient.js +0 -1253
- package/dist/solana/index.d.ts +0 -7
- package/dist/solana/index.js +0 -43
- package/dist/solana/utils.js +0 -211
- package/dist/sui/StreamClient.js +0 -648
- package/dist/sui/constants.js +0 -43
- package/dist/sui/index.d.ts +0 -4
- package/dist/sui/types.js +0 -102
- package/dist/sui/wallet.js +0 -90
- /package/dist/{common → cjs/common}/types.js +0 -0
- /package/dist/{evm → cjs/evm}/abi.js +0 -0
- /package/dist/{evm → cjs/evm}/ercAbi.js +0 -0
- /package/dist/{solana → cjs/solana}/instructionTypes.js +0 -0
- /package/dist/{solana → cjs/solana}/timelockIDL.js +0 -0
- /package/dist/{__tests__ → esm/__tests__}/aptos/streamClient.spec.d.ts +0 -0
- /package/dist/{__tests__ → esm/__tests__}/common/GenericStreamClient.spec.d.ts +0 -0
- /package/dist/{aptos → esm/aptos}/utils.d.ts +0 -0
- /package/dist/{aptos → esm/aptos}/wallet.d.ts +0 -0
- /package/dist/{evm → esm/evm}/abi.d.ts +0 -0
- /package/dist/{evm → esm/evm}/ercAbi.d.ts +0 -0
- /package/dist/{evm → esm/evm}/utils.d.ts +0 -0
- /package/dist/{solana → esm/solana}/instructionTypes.d.ts +0 -0
- /package/dist/{solana → esm/solana}/timelockIDL.d.ts +0 -0
package/README.md
CHANGED
|
@@ -22,8 +22,7 @@ API Documentation available here: [docs site →](https://streamflow-finance.git
|
|
|
22
22
|
Most common imports:
|
|
23
23
|
|
|
24
24
|
```javascript
|
|
25
|
-
import {
|
|
26
|
-
import { GenericStreamClient, getBN, getNumberFromBN } from "@streamflow/stream";
|
|
25
|
+
import { Types, GenericStreamClient, getScaledBigNumber, getNumberFromBigNumber } from "@streamflow/stream";
|
|
27
26
|
```
|
|
28
27
|
|
|
29
28
|
_Check the SDK for other types and utility functions._
|
|
@@ -125,11 +124,11 @@ const createStreamParams: Types.ICreateStreamData = {
|
|
|
125
124
|
recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Recipient address.
|
|
126
125
|
tokenId: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // Token mint address.
|
|
127
126
|
start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
|
|
128
|
-
amount:
|
|
127
|
+
amount: getScaledBigNumber(100, 9), // depositing 100 tokens with 9 decimals mint.
|
|
129
128
|
period: 1, // Time step (period) in seconds per which the unlocking occurs.
|
|
130
129
|
cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds.
|
|
131
|
-
cliffAmount:
|
|
132
|
-
amountPerPeriod:
|
|
130
|
+
cliffAmount: 10, // Amount unlocked at the "cliff" timestamp.
|
|
131
|
+
amountPerPeriod: getScaledBigNumber(5, 9), // Release rate: how many tokens are unlocked per each period.
|
|
133
132
|
name: "Transfer to Jane Doe.", // The stream name or subject.
|
|
134
133
|
canTopup: false, // Whether additional tokens can be deposited after creation, setting to FALSE will effectively create a vesting contract.
|
|
135
134
|
canUpdateRate: false, // settings to TRUE allows sender to update amountPerPeriod
|
|
@@ -170,10 +169,10 @@ try {
|
|
|
170
169
|
const recipients = [
|
|
171
170
|
{
|
|
172
171
|
recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Solana recipient address.
|
|
173
|
-
amount:
|
|
172
|
+
amount: getScaledBgNumber(100, 9), // depositing 100 tokens with 9 decimals mint.
|
|
174
173
|
name: "January Payroll", // The stream name/subject.
|
|
175
|
-
cliffAmount:
|
|
176
|
-
amountPerPeriod:
|
|
174
|
+
cliffAmount: getScaledBgNumber(10, 9), // amount released on cliff for this recipient
|
|
175
|
+
amountPerPeriod: getScaledBgNumber(1, 9), //amount released every specified period epoch
|
|
177
176
|
},
|
|
178
177
|
];
|
|
179
178
|
const createMultiStreamsParams: ICreateMultipleStreamData = {
|
|
@@ -235,7 +234,7 @@ interface ICreateResult {
|
|
|
235
234
|
```javascript
|
|
236
235
|
const withdrawStreamParams: Types.IWithdrawData = {
|
|
237
236
|
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier (address) of a stream to be withdrawn from.
|
|
238
|
-
amount:
|
|
237
|
+
amount: getScaledBgNumber(100, 9), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
|
|
239
238
|
};
|
|
240
239
|
|
|
241
240
|
const solanaParams = {
|
|
@@ -266,7 +265,7 @@ try {
|
|
|
266
265
|
```javascript
|
|
267
266
|
const topupStreamParams: ITopUpData = {
|
|
268
267
|
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier (address) of a stream to be topped up.
|
|
269
|
-
amount:
|
|
268
|
+
amount: getScaledBgNumber(100, 9), // Specified amount to topup (increases deposited amount).
|
|
270
269
|
};
|
|
271
270
|
|
|
272
271
|
const solanaParams = {
|
|
@@ -361,7 +360,7 @@ const updateStreamParams: IUpdateData = {
|
|
|
361
360
|
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to update.
|
|
362
361
|
enableAutomaticWithdrawal: true, // [optional], allows to enable AW if it wasn't, disable is not possible
|
|
363
362
|
withdrawFrequency: 60, // [optional], allows to update withdrawal frequency, may result in additional AW fees
|
|
364
|
-
amountPerPeriod:
|
|
363
|
+
amountPerPeriod: getScaledBgNumber(10, 9), // [optional], allows to update release amount effective on next unlock
|
|
365
364
|
}
|
|
366
365
|
|
|
367
366
|
const solanaParams = {
|
|
@@ -406,8 +405,8 @@ const stream = await client.getOne({
|
|
|
406
405
|
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
|
|
407
406
|
});
|
|
408
407
|
|
|
409
|
-
const unlocked = stream.unlocked(tsInSeconds); //
|
|
410
|
-
console.log(
|
|
408
|
+
const unlocked = stream.unlocked(tsInSeconds); // bignumber amount unlocked at the tsInSeconds
|
|
409
|
+
console.log(getNumberFromBigNumber(unlocked, 9));
|
|
411
410
|
```
|
|
412
411
|
|
|
413
412
|
- Note: unlocked amount is determined based on configuration set on creation, no dynamic data is involved.
|
|
@@ -418,8 +417,8 @@ console.log(getNumberFromBN(unlocked, 9));
|
|
|
418
417
|
const stream = await client.getOne({
|
|
419
418
|
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
|
|
420
419
|
});
|
|
421
|
-
const withdrawn = stream.withdrawnAmount; //
|
|
422
|
-
console.log(
|
|
420
|
+
const withdrawn = stream.withdrawnAmount; // big number amount withdrawn already
|
|
421
|
+
console.log(getNumberFromBigNumber(wihtdrawn, 9));
|
|
423
422
|
const remaining = stream.remaining(9); // amount of remaining funds
|
|
424
423
|
console.log(remaining);
|
|
425
424
|
```
|
|
@@ -490,14 +489,10 @@ Streamflow protocol program IDs
|
|
|
490
489
|
| Testnet | 0xf1916c119a6c917d4b36f96ffc0443930745789f3126a716e05a62223c48993a |
|
|
491
490
|
| Mainnet | 0xa283fd6b45f1103176e7ae27e870c89df7c8783b15345e2b13faa81ec25c4fa6 |
|
|
492
491
|
|
|
493
|
-
**All
|
|
492
|
+
**All BigNumber amounts are denominated in their smallest units.**
|
|
494
493
|
|
|
495
494
|
E.g, if the amount is 1 SOL than this amount in lamports is `1000 \* 10^9 = 1_000_000_000.`
|
|
496
495
|
|
|
497
|
-
And `
|
|
496
|
+
And `BigNumber(1_000_000_000)` is used.
|
|
498
497
|
|
|
499
|
-
Use `
|
|
500
|
-
|
|
501
|
-
`getBN(1, 9)` is equal to `new BN(1_000_000_000)`
|
|
502
|
-
|
|
503
|
-
`getNumberFromBN(new BN(1_000_000_000), 9)` will return 1
|
|
498
|
+
Use `getScaledBigNumber` and `getNumberFromBigNumber` utility functions for conversions between `BigNumber` and `Number` types.
|
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
const bignumber_js_1 = require("bignumber.js");
|
|
7
|
+
const vitest_1 = require("vitest");
|
|
8
|
+
const StreamClient_js_1 = __importDefault(require("../../aptos/StreamClient.js"));
|
|
9
|
+
const types_js_1 = require("../../common/types.js");
|
|
10
|
+
(0, vitest_1.describe)("AptosStreamClient", () => {
|
|
11
|
+
(0, vitest_1.describe)("init", () => {
|
|
12
|
+
(0, vitest_1.test)("should successfully create AptosStreamInstance", () => {
|
|
13
|
+
const instance = new StreamClient_js_1.default(types_js_1.ICluster.Devnet);
|
|
14
|
+
(0, vitest_1.expect)(instance).toBeInstanceOf(StreamClient_js_1.default);
|
|
15
|
+
});
|
|
16
|
+
(0, vitest_1.test)("should correctly set passed params", () => {
|
|
17
|
+
const pid = "PID";
|
|
18
|
+
const gas = "30";
|
|
19
|
+
const instance = new StreamClient_js_1.default("https://cluster", types_js_1.ICluster.Devnet, gas, pid);
|
|
20
|
+
(0, vitest_1.expect)(instance.getMaxGas()).toEqual({ max_gas_amount: gas });
|
|
21
|
+
(0, vitest_1.expect)(instance.getProgramId()).toBe(pid);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
(0, vitest_1.describe)("create", () => {
|
|
25
|
+
const pid = "PID";
|
|
26
|
+
const gas = "30";
|
|
27
|
+
let instance = new StreamClient_js_1.default("https://cluster", types_js_1.ICluster.Devnet, gas, pid);
|
|
28
|
+
(0, vitest_1.beforeEach)(() => {
|
|
29
|
+
instance = new StreamClient_js_1.default("https://cluster", types_js_1.ICluster.Devnet, gas, pid);
|
|
30
|
+
});
|
|
31
|
+
(0, vitest_1.test)("should create a stream with passed parameters", async () => {
|
|
32
|
+
// Arrange
|
|
33
|
+
const mockSigner = vitest_1.vi.fn();
|
|
34
|
+
const mockWallet = {
|
|
35
|
+
signAndSubmitTransaction: mockSigner,
|
|
36
|
+
account: { address: "" },
|
|
37
|
+
};
|
|
38
|
+
const mockRecipient = {
|
|
39
|
+
recipient: "0xtest",
|
|
40
|
+
amount: (0, bignumber_js_1.BigNumber)(1000),
|
|
41
|
+
name: "test name",
|
|
42
|
+
cliffAmount: (0, bignumber_js_1.BigNumber)(1),
|
|
43
|
+
amountPerPeriod: (0, bignumber_js_1.BigNumber)(1),
|
|
44
|
+
};
|
|
45
|
+
const mockData = {
|
|
46
|
+
period: 100,
|
|
47
|
+
start: 10,
|
|
48
|
+
cliff: 12,
|
|
49
|
+
cancelableBySender: true,
|
|
50
|
+
cancelableByRecipient: false,
|
|
51
|
+
transferableBySender: false,
|
|
52
|
+
transferableByRecipient: true,
|
|
53
|
+
canTopup: true,
|
|
54
|
+
automaticWithdrawal: false,
|
|
55
|
+
withdrawalFrequency: 10,
|
|
56
|
+
tokenId: "0xtest::token::Token",
|
|
57
|
+
canPause: false,
|
|
58
|
+
canUpdateRate: false,
|
|
59
|
+
};
|
|
60
|
+
const mockReturn = "hash";
|
|
61
|
+
mockSigner.mockResolvedValue({ hash: mockReturn });
|
|
62
|
+
// Act
|
|
63
|
+
const result = await instance.create({
|
|
64
|
+
...mockData,
|
|
65
|
+
...mockRecipient,
|
|
66
|
+
}, { senderWallet: mockWallet });
|
|
67
|
+
// Assert
|
|
68
|
+
(0, vitest_1.expect)(mockSigner).toHaveBeenCalledTimes(1);
|
|
69
|
+
const callParam = mockSigner.mock.calls[0][0];
|
|
70
|
+
const args = callParam.arguments;
|
|
71
|
+
delete callParam.arguments;
|
|
72
|
+
args.shift();
|
|
73
|
+
(0, vitest_1.expect)(args).toEqual([
|
|
74
|
+
mockRecipient.amount.toString(),
|
|
75
|
+
100,
|
|
76
|
+
mockRecipient.amountPerPeriod.toString(),
|
|
77
|
+
10,
|
|
78
|
+
mockRecipient.cliffAmount.toString(),
|
|
79
|
+
true,
|
|
80
|
+
false,
|
|
81
|
+
false,
|
|
82
|
+
true,
|
|
83
|
+
true,
|
|
84
|
+
false,
|
|
85
|
+
false,
|
|
86
|
+
false,
|
|
87
|
+
10,
|
|
88
|
+
"test name",
|
|
89
|
+
"0xtest",
|
|
90
|
+
]);
|
|
91
|
+
(0, vitest_1.expect)(callParam).toEqual({
|
|
92
|
+
function: "PID::protocol::create",
|
|
93
|
+
type: "create",
|
|
94
|
+
type_arguments: ["0xtest::token::Token"],
|
|
95
|
+
});
|
|
96
|
+
(0, vitest_1.expect)(result.txId).toEqual(mockReturn);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
// describe("createMultiple", () => {
|
|
100
|
+
// });
|
|
101
|
+
// describe("withdraw", () => {
|
|
102
|
+
// });
|
|
103
|
+
// describe("cancel", () => {
|
|
104
|
+
// });
|
|
105
|
+
// describe("transfer", () => {
|
|
106
|
+
// });
|
|
107
|
+
// describe("topup", () => {
|
|
108
|
+
// });
|
|
109
|
+
// describe("getOne", () => {
|
|
110
|
+
// });
|
|
111
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
const ethers_1 = require("ethers");
|
|
7
|
+
const vitest_1 = require("vitest");
|
|
8
|
+
const index_js_1 = require("../../index.js");
|
|
9
|
+
const GenericStreamClient_js_1 = __importDefault(require("../../common/GenericStreamClient.js"));
|
|
10
|
+
const types_js_1 = require("../../common/types.js");
|
|
11
|
+
(0, vitest_1.describe)("GenericStreamClient", () => {
|
|
12
|
+
vitest_1.describe.each([
|
|
13
|
+
{
|
|
14
|
+
chain: types_js_1.IChain.Aptos,
|
|
15
|
+
cluster: types_js_1.ICluster.Devnet,
|
|
16
|
+
clusterUrl: "https://cluster",
|
|
17
|
+
expected: index_js_1.StreamflowAptos.AptosStreamClient,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
chain: types_js_1.IChain.Solana,
|
|
21
|
+
cluster: types_js_1.ICluster.Devnet,
|
|
22
|
+
clusterUrl: "https://cluster",
|
|
23
|
+
expected: index_js_1.StreamflowSolana.SolanaStreamClient,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
chain: types_js_1.IChain.Ethereum,
|
|
27
|
+
cluster: types_js_1.ICluster.Devnet,
|
|
28
|
+
clusterUrl: "https://cluster",
|
|
29
|
+
signer: ethers_1.Wallet.createRandom(),
|
|
30
|
+
expected: index_js_1.StreamflowEVM.EvmStreamClient,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
chain: types_js_1.IChain.Sui,
|
|
34
|
+
cluster: types_js_1.ICluster.Devnet,
|
|
35
|
+
clusterUrl: "https://cluster",
|
|
36
|
+
expected: index_js_1.StreamflowSui.SuiStreamClient,
|
|
37
|
+
},
|
|
38
|
+
])(".init($chain)", (config) => {
|
|
39
|
+
(0, vitest_1.test)("should successfully create GenericStreamClient instance", () => {
|
|
40
|
+
const instance = new GenericStreamClient_js_1.default(config);
|
|
41
|
+
(0, vitest_1.expect)(instance).toBeInstanceOf(GenericStreamClient_js_1.default);
|
|
42
|
+
(0, vitest_1.expect)(instance.nativeStreamClient).toBeInstanceOf(config.expected);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const aptos_1 = require("aptos");
|
|
4
|
+
const BaseStreamClient_js_1 = require("../common/BaseStreamClient.js");
|
|
5
|
+
const types_js_1 = require("../common/types.js");
|
|
6
|
+
const constants_js_1 = require("./constants.js");
|
|
7
|
+
const types_js_2 = require("./types.js");
|
|
8
|
+
const wallet_js_1 = require("./wallet.js");
|
|
9
|
+
const utils_js_1 = require("./utils.js");
|
|
10
|
+
const constants_js_2 = require("../common/constants.js");
|
|
11
|
+
class AptosStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
12
|
+
constructor(clusterUrl, cluster = types_js_1.ICluster.Mainnet, maxGas = "10000", programId) {
|
|
13
|
+
super();
|
|
14
|
+
this.programId = programId ? programId : constants_js_1.APTOS_PROGRAM_IDS[cluster];
|
|
15
|
+
this.maxGas = maxGas;
|
|
16
|
+
this.client = new aptos_1.AptosClient(clusterUrl);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new stream/vesting contract.
|
|
20
|
+
*/
|
|
21
|
+
async create(streamData, { senderWallet }) {
|
|
22
|
+
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
23
|
+
const [metadataId, payload] = this.generateMultiPayloads({
|
|
24
|
+
...streamData,
|
|
25
|
+
recipients: [{ ...streamData }],
|
|
26
|
+
}, wallet)[0];
|
|
27
|
+
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
28
|
+
return { ixs: [payload], txId: hash, metadataId };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates multiple stream/vesting contracts.
|
|
32
|
+
*/
|
|
33
|
+
async createMultiple(multipleStreamData, { senderWallet }) {
|
|
34
|
+
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
35
|
+
const payloads = this.generateMultiPayloads(multipleStreamData, wallet);
|
|
36
|
+
const txs = [];
|
|
37
|
+
const metadatas = [];
|
|
38
|
+
const metadataToRecipient = {};
|
|
39
|
+
const errors = [];
|
|
40
|
+
for (let i = 0; i < payloads.length; i++) {
|
|
41
|
+
const [metadataId, payload] = payloads[i];
|
|
42
|
+
const recipient = multipleStreamData.recipients[i];
|
|
43
|
+
try {
|
|
44
|
+
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
45
|
+
txs.push(hash);
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
errors.push({
|
|
49
|
+
error: e?.toString() ?? "Unknown error!",
|
|
50
|
+
recipient: recipient.recipient,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
metadatas.push(metadataId);
|
|
55
|
+
metadataToRecipient[metadataId] = recipient;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
txs,
|
|
60
|
+
metadatas,
|
|
61
|
+
metadataToRecipient,
|
|
62
|
+
errors,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Attempts withdrawing from the specified stream.
|
|
67
|
+
*/
|
|
68
|
+
async withdraw({ id, amount = constants_js_2.WITHDRAW_AVAILABLE_AMOUNT }, { senderWallet, tokenId }) {
|
|
69
|
+
const payload = {
|
|
70
|
+
type: "withdraw",
|
|
71
|
+
function: `${this.programId}::protocol::withdraw`,
|
|
72
|
+
type_arguments: [tokenId],
|
|
73
|
+
arguments: [id, amount.toString()],
|
|
74
|
+
};
|
|
75
|
+
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
76
|
+
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
77
|
+
return { ixs: [payload], txId: hash };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Attempts canceling the specified stream.
|
|
81
|
+
*/
|
|
82
|
+
async cancel(cancelData, { senderWallet, tokenId }) {
|
|
83
|
+
const payload = {
|
|
84
|
+
type: "cancel",
|
|
85
|
+
function: `${this.programId}::protocol::cancel`,
|
|
86
|
+
type_arguments: [tokenId],
|
|
87
|
+
arguments: [cancelData.id],
|
|
88
|
+
};
|
|
89
|
+
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
90
|
+
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
91
|
+
return { ixs: [payload], txId: hash };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
95
|
+
*/
|
|
96
|
+
async transfer(transferData, { senderWallet, tokenId }) {
|
|
97
|
+
const payload = {
|
|
98
|
+
type: "transfer",
|
|
99
|
+
function: `${this.programId}::protocol::transfer`,
|
|
100
|
+
type_arguments: [tokenId],
|
|
101
|
+
arguments: [transferData.id, transferData.newRecipient],
|
|
102
|
+
};
|
|
103
|
+
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
104
|
+
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
105
|
+
return { ixs: [payload], txId: hash };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Tops up stream account with specified amount.
|
|
109
|
+
*/
|
|
110
|
+
async topup(topupData, { senderWallet, tokenId }) {
|
|
111
|
+
const payload = {
|
|
112
|
+
type: "topup",
|
|
113
|
+
function: `${this.programId}::protocol::topup`,
|
|
114
|
+
type_arguments: [tokenId],
|
|
115
|
+
arguments: [topupData.id, topupData.amount.toString()],
|
|
116
|
+
};
|
|
117
|
+
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
118
|
+
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
119
|
+
return { ixs: [payload], txId: hash };
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Fetch stream data by its id (address).
|
|
123
|
+
*/
|
|
124
|
+
async getOne({ id }) {
|
|
125
|
+
const contractResources = await this.client.getAccountResources(id);
|
|
126
|
+
const contract = contractResources.find((r) => r.type.includes("protocol::Contract"));
|
|
127
|
+
if (!contract) {
|
|
128
|
+
throw new Error(`Contract with id ${id} could not be found!`);
|
|
129
|
+
}
|
|
130
|
+
const tokenIdMatch = contract.type.match(/0x[0-9a-f]+::protocol::Contract<(.*)>/);
|
|
131
|
+
const tokenId = tokenIdMatch?.[1] ?? "";
|
|
132
|
+
const { data } = contract;
|
|
133
|
+
return new types_js_2.Contract(data, tokenId);
|
|
134
|
+
}
|
|
135
|
+
async get() {
|
|
136
|
+
throw new Error("Get all method is not supported for Aptos chain!");
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Attempts updating the stream auto withdrawal params and amount per period
|
|
140
|
+
*/
|
|
141
|
+
async update(updateData, { senderWallet, tokenId }) {
|
|
142
|
+
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
143
|
+
const payload = {
|
|
144
|
+
type: "update",
|
|
145
|
+
function: `${this.programId}::protocol::update`,
|
|
146
|
+
type_arguments: [tokenId],
|
|
147
|
+
arguments: [
|
|
148
|
+
updateData.id,
|
|
149
|
+
updateData.enableAutomaticWithdrawal ? [true] : [],
|
|
150
|
+
updateData.withdrawFrequency ? [updateData.withdrawFrequency.toString()] : [],
|
|
151
|
+
updateData.amountPerPeriod ? [updateData.amountPerPeriod.toString()] : [],
|
|
152
|
+
],
|
|
153
|
+
};
|
|
154
|
+
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
155
|
+
return { ixs: [payload], txId: hash };
|
|
156
|
+
}
|
|
157
|
+
async getFees({ address }) {
|
|
158
|
+
const resource = await this.client.getAccountResource(this.programId, `${this.programId}::fees::FeeTable`);
|
|
159
|
+
const data = resource.data;
|
|
160
|
+
const value = await this.client.getTableItem(data.values.handle, {
|
|
161
|
+
key_type: "address",
|
|
162
|
+
key: address,
|
|
163
|
+
value_type: "u64",
|
|
164
|
+
});
|
|
165
|
+
if (!value) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
return { streamflowFee: Number(value) / 100, partnerFee: 0 };
|
|
169
|
+
}
|
|
170
|
+
async getDefaultStreamflowFee() {
|
|
171
|
+
const resource = await this.client.getAccountResource(this.programId, `${this.programId}::admin::ConfigV2`);
|
|
172
|
+
return Number(resource.data.streamflow_fees) / 100;
|
|
173
|
+
}
|
|
174
|
+
extractErrorCode(err) {
|
|
175
|
+
return (0, utils_js_1.extractAptosErrorCode)(err.toString() ?? "Unknown error!");
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Returns StreamClient protocol program ID.
|
|
179
|
+
*/
|
|
180
|
+
getProgramId() {
|
|
181
|
+
return this.programId;
|
|
182
|
+
}
|
|
183
|
+
getMaxGas() {
|
|
184
|
+
return { max_gas_amount: this.maxGas };
|
|
185
|
+
}
|
|
186
|
+
// Utility function to prepare transaction payloads for multiple recipients.
|
|
187
|
+
generateMultiPayloads(multipleStreamData, wallet) {
|
|
188
|
+
return multipleStreamData.recipients.map((recipient) => {
|
|
189
|
+
const acc = new aptos_1.AptosAccount(); // Generate random address as seeds for deriving "escrow" account
|
|
190
|
+
const seeds = acc.address();
|
|
191
|
+
const encoder = new TextEncoder();
|
|
192
|
+
// A workaround to pass a String in seeds because different wallets seem
|
|
193
|
+
// to serialize vector<u8> differently and String should be safer that Uin8Array
|
|
194
|
+
const actualSeeds = encoder.encode(seeds.hex());
|
|
195
|
+
const metadataId = aptos_1.AptosAccount.getResourceAccountAddress(wallet.address, actualSeeds);
|
|
196
|
+
return [
|
|
197
|
+
metadataId.toString(),
|
|
198
|
+
{
|
|
199
|
+
type: "create",
|
|
200
|
+
function: `${this.programId}::protocol::create`,
|
|
201
|
+
type_arguments: [multipleStreamData.tokenId],
|
|
202
|
+
arguments: [
|
|
203
|
+
seeds.hex(),
|
|
204
|
+
recipient.amount.toString(),
|
|
205
|
+
multipleStreamData.period,
|
|
206
|
+
recipient.amountPerPeriod.toString(),
|
|
207
|
+
multipleStreamData.start,
|
|
208
|
+
recipient.cliffAmount.toString(),
|
|
209
|
+
multipleStreamData.cancelableBySender,
|
|
210
|
+
multipleStreamData.cancelableByRecipient,
|
|
211
|
+
multipleStreamData.transferableBySender,
|
|
212
|
+
multipleStreamData.transferableByRecipient,
|
|
213
|
+
multipleStreamData.canTopup,
|
|
214
|
+
multipleStreamData.canPause || false,
|
|
215
|
+
multipleStreamData.canUpdateRate || false,
|
|
216
|
+
multipleStreamData.automaticWithdrawal || false,
|
|
217
|
+
multipleStreamData.withdrawalFrequency || 0,
|
|
218
|
+
recipient.name,
|
|
219
|
+
recipient.recipient,
|
|
220
|
+
],
|
|
221
|
+
},
|
|
222
|
+
];
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
exports.default = AptosStreamClient;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.APTOS_MODULE_ERROR_MAP = exports.APTOS_ERROR_MATCH_REGEX = exports.APTOS_PROGRAM_IDS = void 0;
|
|
4
|
+
const types_js_1 = require("../common/types.js");
|
|
5
|
+
exports.APTOS_PROGRAM_IDS = {
|
|
6
|
+
[types_js_1.ICluster.Mainnet]: "0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0",
|
|
7
|
+
// TODO: Add a correct programID for Test net
|
|
8
|
+
[types_js_1.ICluster.Devnet]: "0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688",
|
|
9
|
+
[types_js_1.ICluster.Testnet]: "0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688",
|
|
10
|
+
[types_js_1.ICluster.Local]: "0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0",
|
|
11
|
+
};
|
|
12
|
+
exports.APTOS_ERROR_MATCH_REGEX = /Move abort in [a-z0-9]+::([^:]+): ([A-Z_]+)/;
|
|
13
|
+
exports.APTOS_MODULE_ERROR_MAP = {
|
|
14
|
+
protocol: {
|
|
15
|
+
1: types_js_1.ContractErrorCode.ECONTRACT_NOT_INIT,
|
|
16
|
+
2: types_js_1.ContractErrorCode.EBAD_AMOUNT,
|
|
17
|
+
3: types_js_1.ContractErrorCode.ENO_PERMISSIONS,
|
|
18
|
+
4: types_js_1.ContractErrorCode.EBADINPUT,
|
|
19
|
+
5: types_js_1.ContractErrorCode.ECLOSED,
|
|
20
|
+
6: types_js_1.ContractErrorCode.EBAD_INPUT_AMOUNT_PER_PERIOD,
|
|
21
|
+
8: types_js_1.ContractErrorCode.EBAD_INPUT_UPDATE_RATE,
|
|
22
|
+
9: types_js_1.ContractErrorCode.EBAD_INPUT_CLIFF_AMOUNT,
|
|
23
|
+
10: types_js_1.ContractErrorCode.EBAD_INPUT_PERIOD,
|
|
24
|
+
11: types_js_1.ContractErrorCode.EBAD_INPUT_START,
|
|
25
|
+
12: types_js_1.ContractErrorCode.ENO_RECIPIENT_COIN_ADDRESS,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -30,9 +30,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.constants = exports.AptosStreamClient = exports.default = void 0;
|
|
33
|
-
var
|
|
34
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(
|
|
35
|
-
Object.defineProperty(exports, "AptosStreamClient", { enumerable: true, get: function () { return __importDefault(
|
|
36
|
-
__exportStar(require("./utils"), exports);
|
|
37
|
-
__exportStar(require("./types"), exports);
|
|
38
|
-
exports.constants = __importStar(require("./constants"));
|
|
33
|
+
var StreamClient_js_1 = require("./StreamClient.js");
|
|
34
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(StreamClient_js_1).default; } });
|
|
35
|
+
Object.defineProperty(exports, "AptosStreamClient", { enumerable: true, get: function () { return __importDefault(StreamClient_js_1).default; } });
|
|
36
|
+
__exportStar(require("./utils.js"), exports);
|
|
37
|
+
__exportStar(require("./types.js"), exports);
|
|
38
|
+
exports.constants = __importStar(require("./constants.js"));
|
|
@@ -0,0 +1,69 @@
|
|
|
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 bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
+
const buffer_1 = require("buffer");
|
|
9
|
+
const contractUtils_js_1 = require("../common/contractUtils.js");
|
|
10
|
+
const utils_js_1 = require("./utils.js");
|
|
11
|
+
const utils_js_2 = require("../common/utils.js");
|
|
12
|
+
class Contract {
|
|
13
|
+
constructor(stream, tokenId) {
|
|
14
|
+
this.magic = 0;
|
|
15
|
+
this.version = 0;
|
|
16
|
+
this.createdAt = parseInt(stream.created);
|
|
17
|
+
this.withdrawnAmount = (0, bignumber_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 = (0, utils_js_1.normalizeAptosAddress)(stream.sender);
|
|
22
|
+
this.senderTokens = (0, utils_js_1.normalizeAptosAddress)(stream.sender);
|
|
23
|
+
this.recipient = (0, utils_js_1.normalizeAptosAddress)(stream.recipient);
|
|
24
|
+
this.recipientTokens = (0, utils_js_1.normalizeAptosAddress)(stream.recipient);
|
|
25
|
+
this.mint = tokenId;
|
|
26
|
+
this.escrowTokens = "";
|
|
27
|
+
this.streamflowTreasury = "";
|
|
28
|
+
this.streamflowTreasuryTokens = "";
|
|
29
|
+
this.streamflowFeeTotal = (0, bignumber_js_1.default)(0);
|
|
30
|
+
this.streamflowFeeWithdrawn = (0, bignumber_js_1.default)(0);
|
|
31
|
+
this.streamflowFeePercent = parseInt(stream.fees.streamflow_fee_percentage) / 10000;
|
|
32
|
+
this.partnerFeeTotal = (0, bignumber_js_1.default)(0);
|
|
33
|
+
this.partnerFeeWithdrawn = (0, bignumber_js_1.default)(0);
|
|
34
|
+
this.partnerFeePercent = 0;
|
|
35
|
+
this.partner = "";
|
|
36
|
+
this.partnerTokens = "";
|
|
37
|
+
this.start = parseInt(stream.start);
|
|
38
|
+
this.depositedAmount = (0, bignumber_js_1.default)(stream.amount);
|
|
39
|
+
this.period = parseInt(stream.period);
|
|
40
|
+
this.amountPerPeriod = (0, bignumber_js_1.default)(stream.amount_per_period);
|
|
41
|
+
this.cliff = parseInt(stream.start);
|
|
42
|
+
this.cliffAmount = (0, bignumber_js_1.default)(stream.cliff_amount);
|
|
43
|
+
this.cancelableBySender = stream.meta.cancelable_by_sender;
|
|
44
|
+
this.cancelableByRecipient = stream.meta.cancelable_by_recipient;
|
|
45
|
+
this.automaticWithdrawal = stream.meta.automatic_withdrawal;
|
|
46
|
+
this.transferableBySender = stream.meta.transferable_by_sender;
|
|
47
|
+
this.transferableByRecipient = stream.meta.transferable_by_recipient;
|
|
48
|
+
this.canTopup = stream.meta.can_topup;
|
|
49
|
+
const name = stream.meta.contract_name.replace("0x", "");
|
|
50
|
+
this.name = buffer_1.Buffer.from(name, "hex").toString("utf8");
|
|
51
|
+
this.withdrawalFrequency = parseInt(stream.meta.withdrawal_frequency);
|
|
52
|
+
this.closed = stream.closed;
|
|
53
|
+
this.currentPauseStart = parseInt(stream.current_pause_start);
|
|
54
|
+
this.pauseCumulative = (0, bignumber_js_1.default)(stream.pause_cumulative);
|
|
55
|
+
this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
|
|
56
|
+
this.fundsUnlockedAtLastRateChange = (0, bignumber_js_1.default)(stream.funds_unlocked_at_last_rate_change);
|
|
57
|
+
this.type = (0, contractUtils_js_1.buildStreamType)(this);
|
|
58
|
+
}
|
|
59
|
+
unlocked(currentTimestamp) {
|
|
60
|
+
return (0, contractUtils_js_1.calculateUnlockedAmount)({
|
|
61
|
+
...this,
|
|
62
|
+
currentTimestamp,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
remaining(decimals) {
|
|
66
|
+
return (0, utils_js_2.getNumberFromBigNumber)(this.depositedAmount.minus(this.withdrawnAmount), decimals);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.Contract = Contract;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeAptosAddress = exports.extractAptosErrorCode = void 0;
|
|
4
|
-
|
|
4
|
+
const constants_js_1 = require("./constants.js");
|
|
5
5
|
function extractAptosErrorCode(errorText) {
|
|
6
|
-
|
|
6
|
+
const match = constants_js_1.APTOS_ERROR_MATCH_REGEX.exec(errorText);
|
|
7
7
|
if (!match) {
|
|
8
8
|
return null;
|
|
9
9
|
}
|
|
@@ -25,11 +25,11 @@ function normalizeAptosAddress(address) {
|
|
|
25
25
|
if (isAddressSpecial(address)) {
|
|
26
26
|
return address;
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
const length = address.length;
|
|
29
29
|
if (length === 66 || length < 3) {
|
|
30
30
|
return address;
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
const missingZeros = 66 - length;
|
|
33
33
|
return address.slice(0, 2) + "0".repeat(missingZeros) + address.slice(2);
|
|
34
34
|
}
|
|
35
35
|
exports.normalizeAptosAddress = normalizeAptosAddress;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AptosWalletWrapper = void 0;
|
|
4
|
+
const aptos_1 = require("aptos");
|
|
5
|
+
class AptosWalletWrapper {
|
|
6
|
+
constructor(wallet, client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
this.wallet = wallet;
|
|
9
|
+
if (wallet instanceof aptos_1.AptosAccount) {
|
|
10
|
+
this.address = wallet.address();
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
this.address = wallet.account.address;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async signAndSubmitTransaction(input) {
|
|
17
|
+
if (this.wallet instanceof aptos_1.AptosAccount) {
|
|
18
|
+
const builder = new aptos_1.TransactionBuilderRemoteABI(this.client, {
|
|
19
|
+
sender: this.address,
|
|
20
|
+
});
|
|
21
|
+
const rawTxn = await builder.build(input.function, input.type_arguments, input.arguments);
|
|
22
|
+
const res = await this.client.simulateTransaction(this.wallet, rawTxn);
|
|
23
|
+
if (!res[0].success) {
|
|
24
|
+
throw new Error(`Transaction Simulation failed: ${JSON.stringify(res)}`);
|
|
25
|
+
}
|
|
26
|
+
const signedTx = await this.client.signTransaction(this.wallet, rawTxn);
|
|
27
|
+
const tx = await this.client.submitSignedBCSTransaction(signedTx);
|
|
28
|
+
await this.client.waitForTransaction(tx.hash);
|
|
29
|
+
return tx.hash;
|
|
30
|
+
}
|
|
31
|
+
return (await this.wallet.signAndSubmitTransaction(input)).hash;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.AptosWalletWrapper = AptosWalletWrapper;
|