@ledgerhq/coin-sui 0.15.0-nightly.2 → 0.15.0
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 +25 -12
- package/index.d.ts +0 -0
- package/lib/api/index.js +2 -7
- 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 +0 -38
- package/lib/logic/craftTransaction.integration.test.js.map +1 -1
- package/lib/logic/craftTransaction.js +4 -3
- 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 +2 -3
- 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 +3 -10
- package/lib/network/sdk.js.map +1 -1
- package/lib/types/model.d.ts +0 -3
- package/lib/types/model.d.ts.map +1 -1
- package/lib-es/api/index.js +2 -7
- 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 +0 -38
- package/lib-es/logic/craftTransaction.integration.test.js.map +1 -1
- package/lib-es/logic/craftTransaction.js +4 -3
- 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 +2 -3
- 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 +3 -10
- package/lib-es/network/sdk.js.map +1 -1
- package/lib-es/types/model.d.ts +0 -3
- package/lib-es/types/model.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/api/index.test.ts +1 -1
- package/src/api/index.ts +2 -7
- package/src/logic/craftTransaction.integration.test.ts +0 -48
- package/src/logic/craftTransaction.test.ts +25 -41
- package/src/logic/craftTransaction.ts +20 -25
- package/src/logic/estimateFees.integration.test.ts +1 -1
- package/src/network/sdk.integration.test.ts +2 -2
- package/src/network/sdk.ts +4 -22
- package/src/types/model.ts +0 -4
package/src/api/index.test.ts
CHANGED
|
@@ -62,7 +62,7 @@ describe("api/index", () => {
|
|
|
62
62
|
const txIntent = { foo: "bar" } as any;
|
|
63
63
|
const { transaction: result } = await api.craftTransaction(txIntent);
|
|
64
64
|
expect(result).toBe(unsigned.toString("hex"));
|
|
65
|
-
expect(logic.craftTransaction).toHaveBeenCalledWith(txIntent
|
|
65
|
+
expect(logic.craftTransaction).toHaveBeenCalledWith(txIntent);
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
it("should call estimateFees via estimate wrapper and return FeeEstimation", async () => {
|
package/src/api/index.ts
CHANGED
|
@@ -38,14 +38,9 @@ export function createApi(config: SuiConfig): AlpacaApi {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
async function craft(transactionIntent: TransactionIntent): Promise<CraftedTransaction> {
|
|
41
|
-
const { unsigned
|
|
41
|
+
const { unsigned } = await craftTransaction(transactionIntent);
|
|
42
42
|
|
|
43
|
-
return {
|
|
44
|
-
transaction: Buffer.from(unsigned).toString("hex"),
|
|
45
|
-
details: {
|
|
46
|
-
objects: objects?.map(obj => Buffer.from(obj).toString("hex")),
|
|
47
|
-
},
|
|
48
|
-
};
|
|
43
|
+
return { transaction: Buffer.from(unsigned).toString("hex") };
|
|
49
44
|
}
|
|
50
45
|
|
|
51
46
|
async function estimate(transactionIntent: TransactionIntent): Promise<FeeEstimation> {
|
|
@@ -32,7 +32,6 @@ describe("craftTransaction", () => {
|
|
|
32
32
|
|
|
33
33
|
expect(result).toBeDefined();
|
|
34
34
|
expect(result.unsigned).toBeInstanceOf(Uint8Array);
|
|
35
|
-
expect(result.objects).toBeUndefined();
|
|
36
35
|
|
|
37
36
|
const resultCoinTypes = await extractCoinTypeFromUnsignedTx(result.unsigned);
|
|
38
37
|
expect(resultCoinTypes).toEqual(expect.arrayContaining([expect.stringContaining("sui")]));
|
|
@@ -57,53 +56,6 @@ describe("craftTransaction", () => {
|
|
|
57
56
|
|
|
58
57
|
expect(result).toBeDefined();
|
|
59
58
|
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);
|
|
107
59
|
|
|
108
60
|
const resultCoinTypes = await extractCoinTypeFromUnsignedTx(result.unsigned);
|
|
109
61
|
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(
|
|
13
|
+
mockCreateTransaction.mockResolvedValue(mockUnsignedTx);
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it("should create a transaction with correct parameters", async () => {
|
|
@@ -27,16 +27,12 @@ describe("craftTransaction", () => {
|
|
|
27
27
|
asset: { type: "native" },
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
expect(mockCreateTransaction).toHaveBeenCalledWith(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
coinType: "0x2::sui::SUI",
|
|
37
|
-
},
|
|
38
|
-
false,
|
|
39
|
-
);
|
|
30
|
+
expect(mockCreateTransaction).toHaveBeenCalledWith(sender, {
|
|
31
|
+
amount: new BigNumber(amount.toString()),
|
|
32
|
+
recipient,
|
|
33
|
+
mode: type,
|
|
34
|
+
coinType: "0x2::sui::SUI",
|
|
35
|
+
});
|
|
40
36
|
expect(result).toEqual({ unsigned: mockUnsignedTx });
|
|
41
37
|
});
|
|
42
38
|
|
|
@@ -54,16 +50,12 @@ describe("craftTransaction", () => {
|
|
|
54
50
|
asset: { type: "native" },
|
|
55
51
|
});
|
|
56
52
|
|
|
57
|
-
expect(mockCreateTransaction).toHaveBeenCalledWith(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
coinType: "0x2::sui::SUI",
|
|
64
|
-
},
|
|
65
|
-
false,
|
|
66
|
-
);
|
|
53
|
+
expect(mockCreateTransaction).toHaveBeenCalledWith(sender, {
|
|
54
|
+
amount: new BigNumber(amount.toString()),
|
|
55
|
+
recipient,
|
|
56
|
+
mode: type,
|
|
57
|
+
coinType: "0x2::sui::SUI",
|
|
58
|
+
});
|
|
67
59
|
expect(result).toEqual({ unsigned: mockUnsignedTx });
|
|
68
60
|
});
|
|
69
61
|
|
|
@@ -81,16 +73,12 @@ describe("craftTransaction", () => {
|
|
|
81
73
|
asset: { type: "native" },
|
|
82
74
|
});
|
|
83
75
|
|
|
84
|
-
expect(mockCreateTransaction).toHaveBeenCalledWith(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
coinType: "0x2::sui::SUI",
|
|
91
|
-
},
|
|
92
|
-
false,
|
|
93
|
-
);
|
|
76
|
+
expect(mockCreateTransaction).toHaveBeenCalledWith(sender, {
|
|
77
|
+
amount: new BigNumber(amount.toString()),
|
|
78
|
+
recipient,
|
|
79
|
+
mode: type,
|
|
80
|
+
coinType: "0x2::sui::SUI",
|
|
81
|
+
});
|
|
94
82
|
expect(result).toEqual({ unsigned: mockUnsignedTx });
|
|
95
83
|
});
|
|
96
84
|
|
|
@@ -108,16 +96,12 @@ describe("craftTransaction", () => {
|
|
|
108
96
|
asset: { type: "native" },
|
|
109
97
|
});
|
|
110
98
|
|
|
111
|
-
expect(mockCreateTransaction).toHaveBeenCalledWith(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
coinType: "0x2::sui::SUI",
|
|
118
|
-
},
|
|
119
|
-
false,
|
|
120
|
-
);
|
|
99
|
+
expect(mockCreateTransaction).toHaveBeenCalledWith(sender, {
|
|
100
|
+
amount: new BigNumber(amount.toString()),
|
|
101
|
+
recipient,
|
|
102
|
+
mode: type,
|
|
103
|
+
coinType: "0x2::sui::SUI",
|
|
104
|
+
});
|
|
121
105
|
expect(result).toEqual({ unsigned: mockUnsignedTx });
|
|
122
106
|
});
|
|
123
107
|
|
|
@@ -4,33 +4,28 @@ 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
|
-
|
|
18
|
-
},
|
|
19
|
-
withObjects: boolean = false,
|
|
20
|
-
): Promise<CoreTransaction> {
|
|
7
|
+
export async function craftTransaction({
|
|
8
|
+
amount,
|
|
9
|
+
asset,
|
|
10
|
+
recipient,
|
|
11
|
+
sender,
|
|
12
|
+
type,
|
|
13
|
+
...extra
|
|
14
|
+
}: TransactionIntent & {
|
|
15
|
+
useAllAmount?: boolean;
|
|
16
|
+
stakedSuiId?: string;
|
|
17
|
+
}): Promise<CoreTransaction> {
|
|
21
18
|
let coinType = DEFAULT_COIN_TYPE;
|
|
22
19
|
if (asset.type === "token" && asset.assetReference) {
|
|
23
20
|
coinType = asset.assetReference;
|
|
24
21
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
withObjects,
|
|
35
|
-
);
|
|
22
|
+
const unsigned = await suiAPI.createTransaction(sender, {
|
|
23
|
+
amount: BigNumber(amount.toString()),
|
|
24
|
+
coinType,
|
|
25
|
+
mode: type as SuiTransactionMode,
|
|
26
|
+
recipient,
|
|
27
|
+
...extra,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return { unsigned };
|
|
36
31
|
}
|
|
@@ -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 = "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0";
|
|
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
|
|
158
|
+
const 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 = "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0";
|
|
166
166
|
const fakeTransaction = {
|
|
167
167
|
mode: "send" as const,
|
|
168
168
|
family: "sui" as const,
|
package/src/network/sdk.ts
CHANGED
|
@@ -34,19 +34,13 @@ 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 {
|
|
38
|
-
Transaction as TransactionType,
|
|
39
|
-
SuiValidator,
|
|
40
|
-
CreateExtrinsicArg,
|
|
41
|
-
CoreTransaction,
|
|
42
|
-
} from "../types";
|
|
37
|
+
import type { Transaction as TransactionType, SuiValidator, CreateExtrinsicArg } from "../types";
|
|
43
38
|
import { ensureAddressFormat } from "../utils";
|
|
44
39
|
import coinConfig from "../config";
|
|
45
40
|
import { getEnv } from "@ledgerhq/live-env";
|
|
46
41
|
import { SUI_SYSTEM_STATE_OBJECT_ID } from "@mysten/sui/utils";
|
|
47
42
|
import { getCurrentSuiPreloadData } from "../bridge/preload";
|
|
48
43
|
import { ONE_SUI } from "../constants";
|
|
49
|
-
import { getInputObjects } from "@mysten/signers/ledger";
|
|
50
44
|
|
|
51
45
|
const apiMap: Record<string, SuiClient> = {};
|
|
52
46
|
type AsyncApiFunction<T> = (api: SuiClient) => Promise<T>;
|
|
@@ -738,15 +732,10 @@ export const getCoinsForAmount = async (
|
|
|
738
732
|
*
|
|
739
733
|
* @param address - The sender's address
|
|
740
734
|
* @param transaction - The transaction details including recipient, amount, and coin type
|
|
741
|
-
* @param withObjects - Return serialized input objects used in the transaction
|
|
742
735
|
* @returns Promise<TransactionBlock> - A built transaction block ready for execution
|
|
743
736
|
*
|
|
744
737
|
*/
|
|
745
|
-
export const createTransaction = async (
|
|
746
|
-
address: string,
|
|
747
|
-
transaction: CreateExtrinsicArg,
|
|
748
|
-
withObjects: boolean = false,
|
|
749
|
-
): Promise<CoreTransaction> =>
|
|
738
|
+
export const createTransaction = async (address: string, transaction: CreateExtrinsicArg) =>
|
|
750
739
|
withApi(async api => {
|
|
751
740
|
const tx = new Transaction();
|
|
752
741
|
tx.setSender(ensureAddressFormat(address));
|
|
@@ -811,14 +800,7 @@ export const createTransaction = async (
|
|
|
811
800
|
}
|
|
812
801
|
}
|
|
813
802
|
|
|
814
|
-
|
|
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 };
|
|
803
|
+
return tx.build({ client: api });
|
|
822
804
|
});
|
|
823
805
|
|
|
824
806
|
/**
|
|
@@ -826,7 +808,7 @@ export const createTransaction = async (
|
|
|
826
808
|
*/
|
|
827
809
|
export const paymentInfo = async (sender: string, fakeTransaction: TransactionType) =>
|
|
828
810
|
withApi(async api => {
|
|
829
|
-
const
|
|
811
|
+
const txb = await createTransaction(sender, fakeTransaction);
|
|
830
812
|
const dryRunTxResponse = await api.dryRunTransactionBlock({ transactionBlock: txb });
|
|
831
813
|
const fees = getTotalGasUsed(dryRunTxResponse.effects);
|
|
832
814
|
|
package/src/types/model.ts
CHANGED
|
@@ -3,9 +3,5 @@ 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. */
|
|
7
6
|
unsigned: Uint8Array;
|
|
8
|
-
|
|
9
|
-
/** The input objects referenced in the transaction, in serialized form.. */
|
|
10
|
-
objects?: Uint8Array[];
|
|
11
7
|
};
|