sdk/js: Added optional Sui package ID parameters to functions
The package IDs can be passed in to avoid fetching them via RPC
This commit is contained in:
parent
817f179b34
commit
55a3ba684e
|
@ -12,16 +12,18 @@ export const publishCoin = async (
|
|||
coreBridgeStateObjectId: string,
|
||||
tokenBridgeStateObjectId: string,
|
||||
decimals: number,
|
||||
signerAddress: string
|
||||
signerAddress: string,
|
||||
coreBridgePackageId?: string,
|
||||
tokenBridgePackageId?: string
|
||||
) => {
|
||||
const coreBridgePackageId = await getPackageId(
|
||||
provider,
|
||||
coreBridgeStateObjectId
|
||||
);
|
||||
const tokenBridgePackageId = await getPackageId(
|
||||
provider,
|
||||
tokenBridgeStateObjectId
|
||||
);
|
||||
[coreBridgePackageId, tokenBridgePackageId] = await Promise.all([
|
||||
coreBridgePackageId
|
||||
? Promise.resolve(coreBridgePackageId)
|
||||
: getPackageId(provider, coreBridgeStateObjectId),
|
||||
tokenBridgePackageId
|
||||
? Promise.resolve(tokenBridgePackageId)
|
||||
: getPackageId(provider, tokenBridgeStateObjectId),
|
||||
]);
|
||||
const build = await getCoinBuildOutput(
|
||||
provider,
|
||||
coreBridgePackageId,
|
||||
|
|
|
@ -345,7 +345,9 @@ describe("Sui SDK tests", () => {
|
|||
suiProvider,
|
||||
SUI_CORE_BRIDGE_STATE_OBJECT_ID,
|
||||
SUI_TOKEN_BRIDGE_STATE_OBJECT_ID,
|
||||
slicedTransferFromEthVAA
|
||||
slicedTransferFromEthVAA,
|
||||
suiCoreBridgePackageId,
|
||||
suiTokenBridgePackageId
|
||||
);
|
||||
const suiRedeemTxResult = await executeTransactionBlock(
|
||||
suiSigner,
|
||||
|
@ -467,7 +469,10 @@ describe("Sui SDK tests", () => {
|
|||
suiProvider,
|
||||
SUI_CORE_BRIDGE_STATE_OBJECT_ID,
|
||||
SUI_TOKEN_BRIDGE_STATE_OBJECT_ID,
|
||||
coin8Type
|
||||
coin8Type,
|
||||
BigInt(0),
|
||||
suiCoreBridgePackageId,
|
||||
suiTokenBridgePackageId
|
||||
);
|
||||
result = await executeTransactionBlock(suiSigner, suiAttestTxPayload);
|
||||
result.effects?.status.status === "failure" &&
|
||||
|
|
|
@ -318,16 +318,22 @@ export async function attestFromSui(
|
|||
coreBridgeStateObjectId: string,
|
||||
tokenBridgeStateObjectId: string,
|
||||
coinType: string,
|
||||
feeAmount: BigInt = BigInt(0)
|
||||
feeAmount: BigInt = BigInt(0),
|
||||
coreBridgePackageId?: string,
|
||||
tokenBridgePackageId?: string
|
||||
): Promise<TransactionBlock> {
|
||||
const metadata = await provider.getCoinMetadata({ coinType });
|
||||
if (metadata === null || metadata.id === null) {
|
||||
throw new Error(`Coin metadata ID for type ${coinType} not found`);
|
||||
}
|
||||
|
||||
const [coreBridgePackageId, tokenBridgePackageId] = await Promise.all([
|
||||
getPackageId(provider, coreBridgeStateObjectId),
|
||||
getPackageId(provider, tokenBridgeStateObjectId),
|
||||
[coreBridgePackageId, tokenBridgePackageId] = await Promise.all([
|
||||
coreBridgePackageId
|
||||
? Promise.resolve(coreBridgePackageId)
|
||||
: getPackageId(provider, coreBridgeStateObjectId),
|
||||
tokenBridgePackageId
|
||||
? Promise.resolve(tokenBridgePackageId)
|
||||
: getPackageId(provider, tokenBridgeStateObjectId),
|
||||
]);
|
||||
const tx = new TransactionBlock();
|
||||
const [feeCoin] = tx.splitCoins(tx.gas, [tx.pure(feeAmount)]);
|
||||
|
|
|
@ -194,11 +194,17 @@ export async function createWrappedOnSui(
|
|||
signerAddress: string,
|
||||
coinPackageId: string,
|
||||
wrappedAssetSetupType: string,
|
||||
attestVAA: Uint8Array
|
||||
attestVAA: Uint8Array,
|
||||
coreBridgePackageId?: string,
|
||||
tokenBridgePackageId?: string
|
||||
): Promise<TransactionBlock> {
|
||||
const [coreBridgePackageId, tokenBridgePackageId] = await Promise.all([
|
||||
getPackageId(provider, coreBridgeStateObjectId),
|
||||
getPackageId(provider, tokenBridgeStateObjectId),
|
||||
[coreBridgePackageId, tokenBridgePackageId] = await Promise.all([
|
||||
coreBridgePackageId
|
||||
? Promise.resolve(coreBridgePackageId)
|
||||
: getPackageId(provider, coreBridgeStateObjectId),
|
||||
tokenBridgePackageId
|
||||
? Promise.resolve(tokenBridgePackageId)
|
||||
: getPackageId(provider, tokenBridgeStateObjectId),
|
||||
]);
|
||||
|
||||
// Get coin metadata
|
||||
|
|
|
@ -367,7 +367,9 @@ export async function redeemOnSui(
|
|||
provider: JsonRpcProvider,
|
||||
coreBridgeStateObjectId: string,
|
||||
tokenBridgeStateObjectId: string,
|
||||
transferVAA: Uint8Array
|
||||
transferVAA: Uint8Array,
|
||||
coreBridgePackageId?: string,
|
||||
tokenBridgePackageId?: string
|
||||
): Promise<TransactionBlock> {
|
||||
const { tokenAddress, tokenChain } = parseTokenTransferVaa(transferVAA);
|
||||
const coinType = await getTokenCoinType(
|
||||
|
@ -380,9 +382,13 @@ export async function redeemOnSui(
|
|||
throw new Error("Unable to fetch token coinType");
|
||||
}
|
||||
|
||||
const [coreBridgePackageId, tokenBridgePackageId] = await Promise.all([
|
||||
getPackageId(provider, coreBridgeStateObjectId),
|
||||
getPackageId(provider, tokenBridgeStateObjectId),
|
||||
[coreBridgePackageId, tokenBridgePackageId] = await Promise.all([
|
||||
coreBridgePackageId
|
||||
? Promise.resolve(coreBridgePackageId)
|
||||
: getPackageId(provider, coreBridgeStateObjectId),
|
||||
tokenBridgePackageId
|
||||
? Promise.resolve(tokenBridgePackageId)
|
||||
: getPackageId(provider, tokenBridgeStateObjectId),
|
||||
]);
|
||||
const tx = new TransactionBlock();
|
||||
const [verifiedVAA] = tx.moveCall({
|
||||
|
|
|
@ -933,7 +933,9 @@ export async function transferFromSui(
|
|||
recipient: Uint8Array,
|
||||
feeAmount: bigint = BigInt(0),
|
||||
relayerFee: bigint = BigInt(0),
|
||||
payload: Uint8Array | null = null
|
||||
payload: Uint8Array | null = null,
|
||||
coreBridgePackageId?: string,
|
||||
tokenBridgePackageId?: string
|
||||
) {
|
||||
if (payload !== null) {
|
||||
throw new Error("Sui transfer with payload not implemented");
|
||||
|
@ -948,9 +950,13 @@ export async function transferFromSui(
|
|||
);
|
||||
}
|
||||
|
||||
const [coreBridgePackageId, tokenBridgePackageId] = await Promise.all([
|
||||
getPackageId(provider, coreBridgeStateObjectId),
|
||||
getPackageId(provider, tokenBridgeStateObjectId),
|
||||
[coreBridgePackageId, tokenBridgePackageId] = await Promise.all([
|
||||
coreBridgePackageId
|
||||
? Promise.resolve(coreBridgePackageId)
|
||||
: getPackageId(provider, coreBridgeStateObjectId),
|
||||
tokenBridgePackageId
|
||||
? Promise.resolve(tokenBridgePackageId)
|
||||
: getPackageId(provider, tokenBridgeStateObjectId),
|
||||
]);
|
||||
const tx = new TransactionBlock();
|
||||
const [transferCoin] = (() => {
|
||||
|
|
|
@ -44,11 +44,17 @@ export async function updateWrappedOnSui(
|
|||
coreBridgeStateObjectId: string,
|
||||
tokenBridgeStateObjectId: string,
|
||||
coinPackageId: string,
|
||||
attestVAA: Uint8Array
|
||||
attestVAA: Uint8Array,
|
||||
coreBridgePackageId?: string,
|
||||
tokenBridgePackageId?: string
|
||||
): Promise<TransactionBlock> {
|
||||
const [coreBridgePackageId, tokenBridgePackageId] = await Promise.all([
|
||||
getPackageId(provider, coreBridgeStateObjectId),
|
||||
getPackageId(provider, tokenBridgeStateObjectId),
|
||||
[coreBridgePackageId, tokenBridgePackageId] = await Promise.all([
|
||||
coreBridgePackageId
|
||||
? Promise.resolve(coreBridgePackageId)
|
||||
: getPackageId(provider, coreBridgeStateObjectId),
|
||||
tokenBridgePackageId
|
||||
? Promise.resolve(tokenBridgePackageId)
|
||||
: getPackageId(provider, tokenBridgeStateObjectId),
|
||||
]);
|
||||
|
||||
// Get coin metadata
|
||||
|
|
Loading…
Reference in New Issue