Skip to content
Open
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
3 changes: 3 additions & 0 deletions tests/HighloadWalletV3.spec.ts

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hy

Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ describe('HighloadWalletV3', () => {
});
it('should be able to go beyond 255 messages with chained internal_transfer', async () => {
const msgCount = getRandomInt(256, 507);
const totalValue = toNano('0.015') * BigInt(msgCount);
const msgs : OutActionSendMsg[] = new Array(msgCount);
const curQuery = new HighloadQueryId();

Expand All @@ -667,10 +668,12 @@ describe('HighloadWalletV3', () => {

expect(res.transactions).toHaveTransaction({
on: highloadWalletV3.address,
value: totalValue,
outMessagesCount: 254
});
expect(res.transactions).toHaveTransaction({
on: highloadWalletV3.address,
value: totalValue - toNano('0.015') * 253n,
outMessagesCount: msgCount - 253
});
for(let i = 0; i < msgCount; i++) {
Expand Down
25 changes: 19 additions & 6 deletions wrappers/HighloadWalletV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ export function highloadWalletV3ConfigToCell(config: HighloadWalletV3Config): Ce
.endCell();
}

function requiredBalance(messages: OutActionSendMsg[]) {
return messages.reduce((accum, cur) => {
let msgVal = 0n;
if(cur.outMsg.info.type == 'internal') {
msgVal = accum + cur.outMsg.info.value.coins;
}
return msgVal;
}, 0n);
}

export class HighloadWalletV3 implements Contract {

constructor(readonly address: Address, readonly init?: { code: Cell; data: Cell }) {
Expand Down Expand Up @@ -110,9 +120,11 @@ export class HighloadWalletV3 implements Contract {
if (createdAt == undefined) {
createdAt = Math.floor(Date.now() / 1000);
}
const totalValue = value == 0n ? requiredBalance(messages) : value;

return await this.sendExternalMessage(provider, secretKey, {
message: this.packActions(messages, value, query_id),
mode: value > 0n ? SendMode.PAY_GAS_SEPARATELY : SendMode.CARRY_ALL_REMAINING_BALANCE,
message: this.packActions(messages, totalValue, query_id),
mode: SendMode.PAY_GAS_SEPARATELY,
query_id: query_id,
createdAt: createdAt,
subwalletId: subwallet,
Expand Down Expand Up @@ -164,14 +176,15 @@ export class HighloadWalletV3 implements Contract {
*/
}

packActions(messages: OutAction[], value: bigint = toNano('1'), query_id: HighloadQueryId) {
let batch: OutAction[];
packActions(messages: OutActionSendMsg[], value: bigint = toNano('1'), query_id: HighloadQueryId) {
let batch: OutActionSendMsg[];
if (messages.length > 254) {
batch = messages.slice(0, 253);
const batchValue = requiredBalance(batch);
batch.push({
type: 'sendMsg',
mode: value > 0n ? SendMode.PAY_GAS_SEPARATELY : SendMode.CARRY_ALL_REMAINING_BALANCE,
outMsg: this.packActions(messages.slice(253), value, query_id)
mode: SendMode.PAY_GAS_SEPARATELY,
outMsg: this.packActions(messages.slice(253), value - batchValue, query_id)
});
} else {
batch = messages;
Expand Down