Skip to content

chore: support tokenApproval for MPC #6161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/abstract-eth/src/abstractEthLikeNewCoins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2531,7 +2531,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
!txParams?.recipients &&
!(
txParams.prebuildTx?.consolidateId ||
(txParams.type && ['acceleration', 'fillNonce', 'transferToken'].includes(txParams.type))
(txParams.type && ['acceleration', 'fillNonce', 'transferToken', 'tokenApproval'].includes(txParams.type))
)
) {
throw new Error(`missing txParams`);
Expand Down
9 changes: 8 additions & 1 deletion modules/sdk-core/src/bitgo/utils/mpcUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export abstract class MpcUtils {
populateIntent(baseCoin: IBaseCoin, params: PrebuildTransactionWithIntentOptions): PopulatedIntent {
const chain = this.baseCoin.getChain();

if (!['acceleration', 'fillNonce', 'transferToken'].includes(params.intentType)) {
if (!['acceleration', 'fillNonce', 'transferToken', 'tokenApproval'].includes(params.intentType)) {
assert(params.recipients, `'recipients' is a required parameter for ${params.intentType} intent`);
}
const intentRecipients = params.recipients?.map((recipient) => {
Expand Down Expand Up @@ -153,6 +153,7 @@ export abstract class MpcUtils {
comment: params.comment,
nonce: params.nonce,
recipients: intentRecipients,
tokenName: params.tokenName,
};

if (baseCoin.getFamily() === 'eth' || baseCoin.getFamily() === 'polygon' || baseCoin.getFamily() === 'bsc') {
Expand All @@ -177,6 +178,12 @@ export abstract class MpcUtils {
receiveAddress: params.receiveAddress,
feeOptions: params.feeOptions,
};
case 'tokenApproval':
return {
...baseIntent,
tokenName: params.tokenName,
feeOptions: params.feeOptions,
};
default:
throw new Error(`Unsupported intent type ${params.intentType}`);
}
Expand Down
1 change: 1 addition & 0 deletions modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export interface PopulatedIntent extends PopulatedIntentBase {
receiveAddress?: string;
custodianTransactionId?: string;
custodianMessageId?: string;
tokenName?: string;
}

export type TxRequestState =
Expand Down
11 changes: 11 additions & 0 deletions modules/sdk-core/src/bitgo/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3313,6 +3313,17 @@ export class Wallet implements IWallet {
params.preview
);
break;
case 'tokenApproval':
txRequest = await this.tssUtils!.prebuildTxWithIntent(
{
reqId,
intentType: 'tokenApproval',
tokenName: params.tokenName,
},
apiVersion,
params.preview
);
break;
default:
throw new Error(`transaction type not supported: ${params.type}`);
}
Expand Down