@ledgerhq/coin-sui 0.14.1-nightly.0 → 0.15.0-nightly.1
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +6 -0
- package/lib/api/index.js +7 -2
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +1 -1
- package/lib/api/index.test.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.integration.test.js +38 -0
- package/lib/logic/craftTransaction.integration.test.js.map +1 -1
- package/lib/logic/craftTransaction.js +3 -4
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransaction.test.js +5 -5
- package/lib/logic/craftTransaction.test.js.map +1 -1
- package/lib/logic/estimateFees.integration.test.js +1 -1
- package/lib/network/index.d.ts +1 -1
- package/lib/network/sdk.d.ts +3 -2
- package/lib/network/sdk.d.ts.map +1 -1
- package/lib/network/sdk.integration.test.js +2 -2
- package/lib/network/sdk.integration.test.js.map +1 -1
- package/lib/network/sdk.js +10 -3
- package/lib/network/sdk.js.map +1 -1
- package/lib/types/model.d.ts +3 -0
- package/lib/types/model.d.ts.map +1 -1
- package/lib-es/api/index.js +7 -2
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +1 -1
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.integration.test.js +38 -0
- package/lib-es/logic/craftTransaction.integration.test.js.map +1 -1
- package/lib-es/logic/craftTransaction.js +3 -4
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransaction.test.js +5 -5
- package/lib-es/logic/craftTransaction.test.js.map +1 -1
- package/lib-es/logic/estimateFees.integration.test.js +1 -1
- package/lib-es/network/index.d.ts +1 -1
- package/lib-es/network/sdk.d.ts +3 -2
- package/lib-es/network/sdk.d.ts.map +1 -1
- package/lib-es/network/sdk.integration.test.js +2 -2
- package/lib-es/network/sdk.integration.test.js.map +1 -1
- package/lib-es/network/sdk.js +10 -3
- package/lib-es/network/sdk.js.map +1 -1
- package/lib-es/types/model.d.ts +3 -0
- package/lib-es/types/model.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/api/index.test.ts +1 -1
- package/src/api/index.ts +7 -2
- package/src/logic/craftTransaction.integration.test.ts +48 -0
- package/src/logic/craftTransaction.test.ts +41 -25
- package/src/logic/craftTransaction.ts +25 -20
- package/src/logic/estimateFees.integration.test.ts +1 -1
- package/src/network/sdk.integration.test.ts +2 -2
- package/src/network/sdk.ts +22 -4
- package/src/types/model.ts +4 -0
- package/index.d.ts +0 -0
|
@@ -32,6 +32,7 @@ describe("craftTransaction", () => {
|
|
|
32
32
|
|
|
33
33
|
expect(result).toBeDefined();
|
|
34
34
|
expect(result.unsigned).toBeInstanceOf(Uint8Array);
|
|
35
|
+
expect(result.objects).toBeUndefined();
|
|
35
36
|
|
|
36
37
|
const resultCoinTypes = await extractCoinTypeFromUnsignedTx(result.unsigned);
|
|
37
38
|
expect(resultCoinTypes).toEqual(expect.arrayContaining([expect.stringContaining("sui")]));
|
|
@@ -56,6 +57,53 @@ describe("craftTransaction", () => {
|
|
|
56
57
|
|
|
57
58
|
expect(result).toBeDefined();
|
|
58
59
|
expect(result.unsigned).toBeInstanceOf(Uint8Array);
|
|
60
|
+
expect(result.objects).toBeUndefined();
|
|
61
|
+
|
|
62
|
+
const resultCoinTypes = await extractCoinTypeFromUnsignedTx(result.unsigned);
|
|
63
|
+
expect(resultCoinTypes).toEqual(expect.arrayContaining([expect.stringContaining("usdt")]));
|
|
64
|
+
}, 15000);
|
|
65
|
+
|
|
66
|
+
it("should craft a native SUI send transaction, returning serialized objects when requested", async () => {
|
|
67
|
+
const transactionIntent: TransactionIntent = {
|
|
68
|
+
sender: SENDER,
|
|
69
|
+
recipient: RECIPIENT,
|
|
70
|
+
amount: BigInt(1000),
|
|
71
|
+
type: "send",
|
|
72
|
+
asset: { type: "native" },
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const result = await craftTransaction(transactionIntent, true);
|
|
76
|
+
|
|
77
|
+
expect(result).toBeDefined();
|
|
78
|
+
expect(result.unsigned).toBeInstanceOf(Uint8Array);
|
|
79
|
+
expect(result.objects).toBeDefined();
|
|
80
|
+
expect(result.objects?.length).toBeGreaterThan(0);
|
|
81
|
+
|
|
82
|
+
const resultCoinTypes = await extractCoinTypeFromUnsignedTx(result.unsigned);
|
|
83
|
+
expect(resultCoinTypes).toEqual(expect.arrayContaining([expect.stringContaining("sui")]));
|
|
84
|
+
}, 15000);
|
|
85
|
+
|
|
86
|
+
it("should craft a token send transaction, returning serialized objects when requested", async () => {
|
|
87
|
+
const coinType =
|
|
88
|
+
"0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT";
|
|
89
|
+
|
|
90
|
+
const transactionIntent: TransactionIntent = {
|
|
91
|
+
sender: SENDER,
|
|
92
|
+
recipient: RECIPIENT,
|
|
93
|
+
amount: BigInt(1000),
|
|
94
|
+
type: "send",
|
|
95
|
+
asset: {
|
|
96
|
+
type: "token",
|
|
97
|
+
assetReference: coinType,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const result = await craftTransaction(transactionIntent, true);
|
|
102
|
+
|
|
103
|
+
expect(result).toBeDefined();
|
|
104
|
+
expect(result.unsigned).toBeInstanceOf(Uint8Array);
|
|
105
|
+
expect(result.objects).toBeDefined();
|
|
106
|
+
expect(result.objects?.length).toBeGreaterThan(0);
|
|
59
107
|
|
|
60
108
|
const resultCoinTypes = await extractCoinTypeFromUnsignedTx(result.unsigned);
|
|
61
109
|
expect(resultCoinTypes).toEqual(expect.arrayContaining([expect.stringContaining("usdt")]));
|
|
@@ -10,7 +10,7 @@ describe("craftTransaction", () => {
|
|
|
10
10
|
|
|
11
11
|
beforeEach(() => {
|
|
12
12
|
jest.clearAllMocks();
|
|
13
|
-
mockCreateTransaction.mockResolvedValue(mockUnsignedTx);
|
|
13
|
+
mockCreateTransaction.mockResolvedValue({ unsigned: mockUnsignedTx });
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it("should create a transaction with correct parameters", async () => {
|
|
@@ -27,12 +27,16 @@ describe("craftTransaction", () => {
|
|
|
27
27
|
asset: { type: "native" },
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
expect(mockCreateTransaction).toHaveBeenCalledWith(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
expect(mockCreateTransaction).toHaveBeenCalledWith(
|
|
31
|
+
sender,
|
|
32
|
+
{
|
|
33
|
+
amount: new BigNumber(amount.toString()),
|
|
34
|
+
recipient,
|
|
35
|
+
mode: type,
|
|
36
|
+
coinType: "0x2::sui::SUI",
|
|
37
|
+
},
|
|
38
|
+
false,
|
|
39
|
+
);
|
|
36
40
|
expect(result).toEqual({ unsigned: mockUnsignedTx });
|
|
37
41
|
});
|
|
38
42
|
|
|
@@ -50,12 +54,16 @@ describe("craftTransaction", () => {
|
|
|
50
54
|
asset: { type: "native" },
|
|
51
55
|
});
|
|
52
56
|
|
|
53
|
-
expect(mockCreateTransaction).toHaveBeenCalledWith(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
expect(mockCreateTransaction).toHaveBeenCalledWith(
|
|
58
|
+
sender,
|
|
59
|
+
{
|
|
60
|
+
amount: new BigNumber(amount.toString()),
|
|
61
|
+
recipient,
|
|
62
|
+
mode: type,
|
|
63
|
+
coinType: "0x2::sui::SUI",
|
|
64
|
+
},
|
|
65
|
+
false,
|
|
66
|
+
);
|
|
59
67
|
expect(result).toEqual({ unsigned: mockUnsignedTx });
|
|
60
68
|
});
|
|
61
69
|
|
|
@@ -73,12 +81,16 @@ describe("craftTransaction", () => {
|
|
|
73
81
|
asset: { type: "native" },
|
|
74
82
|
});
|
|
75
83
|
|
|
76
|
-
expect(mockCreateTransaction).toHaveBeenCalledWith(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
expect(mockCreateTransaction).toHaveBeenCalledWith(
|
|
85
|
+
sender,
|
|
86
|
+
{
|
|
87
|
+
amount: new BigNumber(amount.toString()),
|
|
88
|
+
recipient,
|
|
89
|
+
mode: type,
|
|
90
|
+
coinType: "0x2::sui::SUI",
|
|
91
|
+
},
|
|
92
|
+
false,
|
|
93
|
+
);
|
|
82
94
|
expect(result).toEqual({ unsigned: mockUnsignedTx });
|
|
83
95
|
});
|
|
84
96
|
|
|
@@ -96,12 +108,16 @@ describe("craftTransaction", () => {
|
|
|
96
108
|
asset: { type: "native" },
|
|
97
109
|
});
|
|
98
110
|
|
|
99
|
-
expect(mockCreateTransaction).toHaveBeenCalledWith(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
111
|
+
expect(mockCreateTransaction).toHaveBeenCalledWith(
|
|
112
|
+
sender,
|
|
113
|
+
{
|
|
114
|
+
amount: new BigNumber(amount.toString()),
|
|
115
|
+
recipient,
|
|
116
|
+
mode: type,
|
|
117
|
+
coinType: "0x2::sui::SUI",
|
|
118
|
+
},
|
|
119
|
+
false,
|
|
120
|
+
);
|
|
105
121
|
expect(result).toEqual({ unsigned: mockUnsignedTx });
|
|
106
122
|
});
|
|
107
123
|
|
|
@@ -4,28 +4,33 @@ import type { SuiTransactionMode, CoreTransaction } from "../types";
|
|
|
4
4
|
import suiAPI from "../network";
|
|
5
5
|
import { DEFAULT_COIN_TYPE } from "../network/sdk";
|
|
6
6
|
|
|
7
|
-
export async function craftTransaction(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
export async function craftTransaction(
|
|
8
|
+
{
|
|
9
|
+
amount,
|
|
10
|
+
asset,
|
|
11
|
+
recipient,
|
|
12
|
+
sender,
|
|
13
|
+
type,
|
|
14
|
+
...extra
|
|
15
|
+
}: TransactionIntent & {
|
|
16
|
+
useAllAmount?: boolean;
|
|
17
|
+
stakedSuiId?: string;
|
|
18
|
+
},
|
|
19
|
+
withObjects: boolean = false,
|
|
20
|
+
): Promise<CoreTransaction> {
|
|
18
21
|
let coinType = DEFAULT_COIN_TYPE;
|
|
19
22
|
if (asset.type === "token" && asset.assetReference) {
|
|
20
23
|
coinType = asset.assetReference;
|
|
21
24
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
return suiAPI.createTransaction(
|
|
26
|
+
sender,
|
|
27
|
+
{
|
|
28
|
+
amount: BigNumber(amount.toString()),
|
|
29
|
+
coinType,
|
|
30
|
+
mode: type as SuiTransactionMode,
|
|
31
|
+
recipient,
|
|
32
|
+
...extra,
|
|
33
|
+
},
|
|
34
|
+
withObjects,
|
|
35
|
+
);
|
|
31
36
|
}
|
|
@@ -3,7 +3,7 @@ import { getFullnodeUrl } from "@mysten/sui/client";
|
|
|
3
3
|
import coinConfig from "../config";
|
|
4
4
|
import { estimateFees } from "./estimateFees";
|
|
5
5
|
|
|
6
|
-
const SENDER = "
|
|
6
|
+
const SENDER = "0xad79719ac7edb44f6e253f1f771e8291e281a6aaf1e4789b52bf85336f525e8e";
|
|
7
7
|
const RECIPIENT = "0x33444cf803c690db96527cec67e3c9ab512596f4ba2d4eace43f0b4f716e0164";
|
|
8
8
|
|
|
9
9
|
describe("estimateFees", () => {
|
|
@@ -155,14 +155,14 @@ describe("SUI SDK Integration tests", () => {
|
|
|
155
155
|
recipient: "0x33444cf803c690db96527cec67e3c9ab512596f4ba2d4eace43f0b4f716e0164",
|
|
156
156
|
errors: {},
|
|
157
157
|
};
|
|
158
|
-
const tx = await createTransaction(address, transaction);
|
|
158
|
+
const { unsigned: tx } = await createTransaction(address, transaction);
|
|
159
159
|
expect(tx).toBeInstanceOf(Uint8Array);
|
|
160
160
|
});
|
|
161
161
|
});
|
|
162
162
|
|
|
163
163
|
describe("paymentInfo", () => {
|
|
164
164
|
test("paymentInfo should return gas budget and fees", async () => {
|
|
165
|
-
const sender = "
|
|
165
|
+
const sender = "0xad79719ac7edb44f6e253f1f771e8291e281a6aaf1e4789b52bf85336f525e8e";
|
|
166
166
|
const fakeTransaction = {
|
|
167
167
|
mode: "send" as const,
|
|
168
168
|
family: "sui" as const,
|
package/src/network/sdk.ts
CHANGED
|
@@ -34,13 +34,19 @@ import uniqBy from "lodash/unionBy";
|
|
|
34
34
|
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
35
35
|
import { log } from "@ledgerhq/logs";
|
|
36
36
|
import { makeLRUCache, minutes } from "@ledgerhq/live-network/cache";
|
|
37
|
-
import type {
|
|
37
|
+
import type {
|
|
38
|
+
Transaction as TransactionType,
|
|
39
|
+
SuiValidator,
|
|
40
|
+
CreateExtrinsicArg,
|
|
41
|
+
CoreTransaction,
|
|
42
|
+
} from "../types";
|
|
38
43
|
import { ensureAddressFormat } from "../utils";
|
|
39
44
|
import coinConfig from "../config";
|
|
40
45
|
import { getEnv } from "@ledgerhq/live-env";
|
|
41
46
|
import { SUI_SYSTEM_STATE_OBJECT_ID } from "@mysten/sui/utils";
|
|
42
47
|
import { getCurrentSuiPreloadData } from "../bridge/preload";
|
|
43
48
|
import { ONE_SUI } from "../constants";
|
|
49
|
+
import { getInputObjects } from "@mysten/signers/ledger";
|
|
44
50
|
|
|
45
51
|
const apiMap: Record<string, SuiClient> = {};
|
|
46
52
|
type AsyncApiFunction<T> = (api: SuiClient) => Promise<T>;
|
|
@@ -732,10 +738,15 @@ export const getCoinsForAmount = async (
|
|
|
732
738
|
*
|
|
733
739
|
* @param address - The sender's address
|
|
734
740
|
* @param transaction - The transaction details including recipient, amount, and coin type
|
|
741
|
+
* @param withObjects - Return serialized input objects used in the transaction
|
|
735
742
|
* @returns Promise<TransactionBlock> - A built transaction block ready for execution
|
|
736
743
|
*
|
|
737
744
|
*/
|
|
738
|
-
export const createTransaction = async (
|
|
745
|
+
export const createTransaction = async (
|
|
746
|
+
address: string,
|
|
747
|
+
transaction: CreateExtrinsicArg,
|
|
748
|
+
withObjects: boolean = false,
|
|
749
|
+
): Promise<CoreTransaction> =>
|
|
739
750
|
withApi(async api => {
|
|
740
751
|
const tx = new Transaction();
|
|
741
752
|
tx.setSender(ensureAddressFormat(address));
|
|
@@ -800,7 +811,14 @@ export const createTransaction = async (address: string, transaction: CreateExtr
|
|
|
800
811
|
}
|
|
801
812
|
}
|
|
802
813
|
|
|
803
|
-
|
|
814
|
+
const serialized = await tx.build({ client: api });
|
|
815
|
+
|
|
816
|
+
if (withObjects) {
|
|
817
|
+
const { bcsObjects } = await getInputObjects(tx, api);
|
|
818
|
+
return { unsigned: serialized, objects: bcsObjects as Uint8Array[] };
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
return { unsigned: serialized };
|
|
804
822
|
});
|
|
805
823
|
|
|
806
824
|
/**
|
|
@@ -808,7 +826,7 @@ export const createTransaction = async (address: string, transaction: CreateExtr
|
|
|
808
826
|
*/
|
|
809
827
|
export const paymentInfo = async (sender: string, fakeTransaction: TransactionType) =>
|
|
810
828
|
withApi(async api => {
|
|
811
|
-
const txb = await createTransaction(sender, fakeTransaction);
|
|
829
|
+
const { unsigned: txb } = await createTransaction(sender, fakeTransaction);
|
|
812
830
|
const dryRunTxResponse = await api.dryRunTransactionBlock({ transactionBlock: txb });
|
|
813
831
|
const fees = getTotalGasUsed(dryRunTxResponse.effects);
|
|
814
832
|
|
package/src/types/model.ts
CHANGED
|
@@ -3,5 +3,9 @@ export type SuiOperationMode = "send";
|
|
|
3
3
|
export type AccountInfoResponse = Record<string, string>;
|
|
4
4
|
|
|
5
5
|
export type CoreTransaction = {
|
|
6
|
+
/** The transaction in a serialized format, ready to be signed. */
|
|
6
7
|
unsigned: Uint8Array;
|
|
8
|
+
|
|
9
|
+
/** The input objects referenced in the transaction, in serialized form.. */
|
|
10
|
+
objects?: Uint8Array[];
|
|
7
11
|
};
|
package/index.d.ts
DELETED
|
File without changes
|