From 965fc033752737a86ced4de34046787906a17557 Mon Sep 17 00:00:00 2001 From: Takadenoshi Date: Thu, 21 Mar 2024 17:39:16 +0100 Subject: [PATCH 1/3] construct transfers with Pact.modules.coin.transfer --- .../extension/src/providers/kadena/types/kda-token.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/extension/src/providers/kadena/types/kda-token.ts b/packages/extension/src/providers/kadena/types/kda-token.ts index 3f2d1e6c4..4396ba74f 100644 --- a/packages/extension/src/providers/kadena/types/kda-token.ts +++ b/packages/extension/src/providers/kadena/types/kda-token.ts @@ -57,11 +57,9 @@ export class KDAToken extends KDABaseToken { const keySetAccount = to.startsWith("k:") ? to.replace("k:", "") : to; const unsignedTransaction = Pact.builder .execution( - `(coin.transfer-create "${network.displayAddress( - from.address - )}" "${to}" (read-keyset "ks") ${parseFloat(amount).toFixed( - network.options.decimals - )})` + Pact.modules.coin.transfer(network.displayAddress(from.address), to, { + decimal: amount, + }) ) .addData("ks", { keys: accountDetails.data?.guard.keys || [keySetAccount], From cd161a980f1933ceb4030f6ad890933de6fe1928 Mon Sep 17 00:00:00 2001 From: Takadenoshi Date: Thu, 21 Mar 2024 18:18:07 +0100 Subject: [PATCH 2/3] fix to use transfer-create --- .../src/providers/kadena/types/kda-token.ts | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/extension/src/providers/kadena/types/kda-token.ts b/packages/extension/src/providers/kadena/types/kda-token.ts index 4396ba74f..107e9cbed 100644 --- a/packages/extension/src/providers/kadena/types/kda-token.ts +++ b/packages/extension/src/providers/kadena/types/kda-token.ts @@ -1,6 +1,12 @@ import { BaseToken, BaseTokenOptions } from "@/types/base-token"; import KadenaAPI from "@/providers/kadena/libs/api"; -import { ChainId, ICommand, Pact, addSignatures } from "@kadena/client"; +import { + ChainId, + ICommand, + Pact, + addSignatures, + readKeyset, +} from "@kadena/client"; import { EnkryptAccount } from "@enkryptcom/types"; import { blake2AsU8a } from "@polkadot/util-crypto"; import { KadenaNetwork } from "./kadena-network"; @@ -51,20 +57,23 @@ export class KDAToken extends KDABaseToken { network: KadenaNetwork ): Promise { to = network.displayAddress(to); + const toKey = to.replace("k:", ""); const accountDetails = await this.getAccountDetails(to, network); const api = (await network.api()) as KadenaAPI; const chainID = await api.getChainId(); const keySetAccount = to.startsWith("k:") ? to.replace("k:", "") : to; const unsignedTransaction = Pact.builder .execution( - Pact.modules.coin.transfer(network.displayAddress(from.address), to, { - decimal: amount, - }) + Pact.modules.coin["transfer-create"]( + network.displayAddress(from.address), + to, + readKeyset("ks"), + { + decimal: amount, + } + ) ) - .addData("ks", { - keys: accountDetails.data?.guard.keys || [keySetAccount], - pred: accountDetails.data?.guard.pred || "keys-all", - }) + .addKeyset("ks", "keys-all", toKey) .addSigner(from.publicKey.replace("0x", ""), (withCap: any) => [ withCap("coin.TRANSFER", network.displayAddress(from.address), to, { decimal: amount, From 018a705861f4497b5b400c0ce09a05b4b99edf10 Mon Sep 17 00:00:00 2001 From: Takadenoshi Date: Mon, 25 Mar 2024 17:50:17 +0100 Subject: [PATCH 3/3] fix method of getting keyset account --- packages/extension/src/providers/kadena/types/kda-token.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/extension/src/providers/kadena/types/kda-token.ts b/packages/extension/src/providers/kadena/types/kda-token.ts index 107e9cbed..07f7c3e5b 100644 --- a/packages/extension/src/providers/kadena/types/kda-token.ts +++ b/packages/extension/src/providers/kadena/types/kda-token.ts @@ -57,7 +57,6 @@ export class KDAToken extends KDABaseToken { network: KadenaNetwork ): Promise { to = network.displayAddress(to); - const toKey = to.replace("k:", ""); const accountDetails = await this.getAccountDetails(to, network); const api = (await network.api()) as KadenaAPI; const chainID = await api.getChainId(); @@ -73,7 +72,7 @@ export class KDAToken extends KDABaseToken { } ) ) - .addKeyset("ks", "keys-all", toKey) + .addKeyset("ks", "keys-all", keySetAccount) .addSigner(from.publicKey.replace("0x", ""), (withCap: any) => [ withCap("coin.TRANSFER", network.displayAddress(from.address), to, { decimal: amount,