Skip to content
Merged
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
1 change: 1 addition & 0 deletions modules/sdk-coin-ton/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const VESTING_CONTRACT_WALLET_ID = 268;
export const WALLET_ID = 698983191;
export const JETTON_TRANSFER_OPCODE = 0x0f8a7ea5;
export const WITHDRAW_OPCODE = '00001000';
1 change: 1 addition & 0 deletions modules/sdk-coin-ton/src/lib/iface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface TxData {
seqno: number;
expirationTime: number;
publicKey: string;
sub_wallet_id: number;
signature: string;
bounceable: boolean;
}
Expand Down
16 changes: 13 additions & 3 deletions modules/sdk-coin-ton/src/lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Cell } from 'tonweb/dist/types/boc/cell';
import { BaseKey, BaseTransaction, Entry, Recipient, TransactionRecipient, TransactionType } from '@bitgo/sdk-core';
import { BaseCoin as CoinConfig } from '@bitgo/statics';
import { TransactionExplanation, TxData } from './iface';
import { WITHDRAW_OPCODE, WALLET_ID, JETTON_TRANSFER_OPCODE } from './constants';
import { WITHDRAW_OPCODE, WALLET_ID, JETTON_TRANSFER_OPCODE, VESTING_CONTRACT_WALLET_ID } from './constants';

export class Transaction extends BaseTransaction {
public recipient: Recipient;
Expand All @@ -19,6 +19,7 @@ export class Transaction extends BaseTransaction {
sender: string;
publicKey: string;
isV3ContractMessage: boolean;
sub_wallet_id: number;
protected unsignedMessage: string;
protected finalMessage: string;

Expand Down Expand Up @@ -52,6 +53,7 @@ export class Transaction extends BaseTransaction {
amount: this.recipient.amount,
withdrawAmount: this.withdrawAmount,
seqno: this.seqno,
sub_wallet_id: this.sub_wallet_id,
expirationTime: this.expireTime,
publicKey: this.publicKey,
signature: this._signatures[0],
Expand All @@ -72,7 +74,14 @@ export class Transaction extends BaseTransaction {
}

async build(): Promise<void> {
const signingMessage = this.createSigningMessage(WALLET_ID, this.seqno, this.expireTime);
if (!this.sub_wallet_id) {
if (this.isV3ContractMessage) {
this.sub_wallet_id = VESTING_CONTRACT_WALLET_ID;
} else {
this.sub_wallet_id = WALLET_ID;
}
}
const signingMessage = this.createSigningMessage(this.sub_wallet_id, this.seqno, this.expireTime);
const sendMode = 3; // default sendMode
signingMessage.bits.writeUint8(sendMode);
const outMsg = this.createOutMsg(this.recipient.address, this.recipient.amount, this.message);
Expand Down Expand Up @@ -189,6 +198,7 @@ export class Transaction extends BaseTransaction {
this.message = parsed.payload;
this._signatures.push(parsed.signature);
this.bounceable = parsed.bounce;
this.sub_wallet_id = parsed.walletId;
} catch (e) {
throw new Error('invalid raw transaction');
}
Expand Down Expand Up @@ -263,7 +273,7 @@ export class Transaction extends BaseTransaction {
// signing message

const walletId = slice.loadUint(32).toNumber();
if (walletId !== WALLET_ID) throw new Error('invalid walletId');
if (walletId !== WALLET_ID && walletId !== VESTING_CONTRACT_WALLET_ID) throw new Error('invalid walletId');

const expireAt = slice.loadUint(32).toNumber();

Expand Down
4 changes: 4 additions & 0 deletions modules/sdk-coin-ton/src/lib/transactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,8 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
this.transaction.isV3ContractMessage = bool;
return this;
}
subWalletId(id: number): TransactionBuilder {
this.transaction.sub_wallet_id = id;
return this;
}
}
2 changes: 2 additions & 0 deletions modules/sdk-coin-ton/test/unit/transferBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import TonWeb from 'tonweb';
import { TransactionType } from '@bitgo/sdk-core';
import { coins } from '@bitgo/statics';
import { TransactionBuilderFactory, KeyPair } from '../../src';
import { WALLET_ID } from '../../src/lib/constants';
import * as testData from '../resources/ton';
import * as utils from '../../src/lib/utils';

Expand Down Expand Up @@ -258,5 +259,6 @@ describe('Ton Transfer Builder', () => {
jsonTx.seqno.should.equal(3);
jsonTx.expirationTime.should.equal(1761215512);
jsonTx.bounceable.should.equal(true);
jsonTx.sub_wallet_id.should.equal(WALLET_ID);
});
});