Skip to content

Commit c53ea4d

Browse files
committed
Add shared TP.onLockOrBurnTransferFinalize flow
1 parent bf5b83e commit c53ea4d

15 files changed

Lines changed: 395 additions & 387 deletions

File tree

contracts/contracts/ccip/pools/burn_mint_token_pool/contract.tolk

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,11 @@ fun onLockOrBurnTransfer(
117117

118118
val jettonClient = st.jettonClient.load();
119119
st.pendingBurns.set(requestMsg.queryId, BurnMintTokenPool_PendingBurn {
120-
replyTo: requestMsg.replyTo,
121-
request: requestMsg.request,
122-
out: prepared.out.toCell(),
123-
destTokenAmount: prepared.destTokenAmount,
120+
forwardPayload: fwdp,
124121
expectedSender: jettonClient.masterAddress,
125122
}.toCell());
126123

127-
createMessage({
124+
val burnMsg = createMessage({
128125
bounce: true,
129126
value: BurnMintTokenPool_BURN_VALUE,
130127
dest: sender,
@@ -134,7 +131,8 @@ fun onLockOrBurnTransfer(
134131
sendExcessesTo: contract.getAddress(),
135132
customPayload: null,
136133
},
137-
}).send(SEND_MODE_PAY_FEES_SEPARATELY);
134+
});
135+
burnMsg.send(SEND_MODE_PAY_FEES_SEPARATELY);
138136

139137
return st;
140138
}
@@ -197,30 +195,9 @@ fun onReturnExcessesBack(
197195
assert(sender == pending.expectedSender, Error.UnexpectedBurnConfirmationSender);
198196

199197
st.pendingBurns.delete(msg.queryId);
200-
val request = pending.request.load();
201-
202-
emit(TOKEN_POOL_LOCKED_OR_BURNED_TOPIC, TokenPool_LockedOrBurned {
203-
remoteChainSelector: request.remoteChainSelector,
204-
details: TokenPool_LockedOrBurnedDetails {
205-
token: request.localToken,
206-
sender: request.originalSender,
207-
amount: pending.destTokenAmount,
208-
}.toCell(),
209-
});
210198

211-
if (pending.replyTo != null) {
212-
createMessage({
213-
bounce: true,
214-
value: BurnMintTokenPool_REPLY_VALUE,
215-
dest: pending.replyTo!,
216-
body: TokenPool_LockOrBurnResponse {
217-
queryId: msg.queryId,
218-
out: pending.out,
219-
destTokenAmount: pending.destTokenAmount,
220-
},
221-
}).send(SEND_MODE_PAY_FEES_SEPARATELY | SEND_MODE_CARRY_ALL_REMAINING_MESSAGE_VALUE);
222-
}
223-
return;
199+
var pool = loadPool(st);
200+
return pool.onLockOrBurnTransferFinalize(pending.forwardPayload);
224201
}
225202

226203
val mintEntry = st.pendingMints.get(msg.queryId);
@@ -250,7 +227,7 @@ fun onReturnExcessesBack(
250227
bounce: true,
251228
value: BurnMintTokenPool_REPLY_VALUE,
252229
dest: pending.replyTo!,
253-
body: TokenPool_ReleaseOrMintResponse {
230+
body: TokenPool_ReleaseOrMintFinished {
254231
queryId: msg.queryId,
255232
out: pending.out,
256233
},

contracts/contracts/ccip/pools/burn_mint_token_pool/types.tolk

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: BUSL-1.1
22
import "../../../lib/jetton/jetton_client"
3-
import "../../rmn_remote/lib"
3+
import "../messages"
44
import "../types"
55

66
const BurnMintTokenPool_CONTRACT_NAME = "link.chain.ton.ccip.BurnMintTokenPool".literalSlice();
@@ -11,15 +11,12 @@ const BurnMintTokenPool_MINT_VALUE = ton("0.1");
1111
const BurnMintTokenPool_REPLY_VALUE = ton("0.01");
1212

1313
struct BurnMintTokenPool_PendingBurn {
14-
replyTo: address? = null;
15-
request: Cell<TokenPool_LockOrBurnInV1>;
16-
out: Cell<TokenPool_LockOrBurnOutV1>;
17-
destTokenAmount: uint256;
14+
forwardPayload: TokenPool_LockOrBurnForwardPayload;
1815
expectedSender: address;
1916
}
2017

2118
struct BurnMintTokenPool_PendingMint {
22-
replyTo: address? = null;
19+
replyTo: address?;
2320
request: Cell<TokenPool_ReleaseOrMintInV1>;
2421
out: Cell<TokenPool_ReleaseOrMintOutV1>;
2522
expectedSender: address;

contracts/contracts/ccip/pools/events.tolk

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ const TOKEN_POOL_RAMP_ACCESS_UPDATED_TOPIC = stringCrc32("TokenPool_RampAccessUp
1414
const TOKEN_POOL_CURSED_SUBJECTS_UPDATED_TOPIC = stringCrc32("TokenPool_CursedSubjectsUpdated");
1515
const TOKEN_POOL_FINALITY_CONFIG_SET_TOPIC = stringCrc32("TokenPool_FinalityConfigSet");
1616

17-
struct TokenPool_LockedOrBurnedDetails {
18-
token: address;
19-
sender: address;
20-
amount: uint256;
21-
}
22-
2317
// event LockedOrBurned(uint64 indexed remoteChainSelector, address token, address sender, uint256 amount);
2418
// event ReleasedOrMinted(
2519
// uint64 indexed remoteChainSelector, address token, address sender, address recipient, uint256 amount
@@ -29,9 +23,15 @@ struct TokenPool_LockedOrBurned {
2923
details: Cell<TokenPool_LockedOrBurnedDetails>;
3024
}
3125

32-
struct TokenPool_ReleasedOrMintedParticipants {
26+
struct TokenPool_LockedOrBurnedDetails {
27+
token: address;
3328
sender: address;
34-
recipient: address;
29+
amount: uint256;
30+
}
31+
32+
struct TokenPool_ReleasedOrMinted {
33+
remoteChainSelector: uint64;
34+
details: Cell<TokenPool_ReleasedOrMintedDetails>;
3535
}
3636

3737
struct TokenPool_ReleasedOrMintedDetails {
@@ -40,9 +40,9 @@ struct TokenPool_ReleasedOrMintedDetails {
4040
participants: Cell<TokenPool_ReleasedOrMintedParticipants>;
4141
}
4242

43-
struct TokenPool_ReleasedOrMinted {
44-
remoteChainSelector: uint64;
45-
details: Cell<TokenPool_ReleasedOrMintedDetails>;
43+
struct TokenPool_ReleasedOrMintedParticipants {
44+
sender: address;
45+
recipient: address;
4646
}
4747

4848
struct TokenPool_ChainAdded {

contracts/contracts/ccip/pools/lock_release_token_pool/contract.tolk

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ fun onLockOrBurnTransfer(
7777
var isValidPayload = true; // TODO: safely inspect the payload
7878
val fwdps = loadForwardPayloadAsSlice(msg.forwardPayload);
7979
val fwdp = TokenPool_LockOrBurnForwardPayload.fromSlice(fwdps!);
80-
val requestMsg = lazy fwdp.requestMsg.load();
81-
val prepared = lazy fwdp.prepared.load();
8280

8381
// TODO: can we trust (any) JettonWallet forward payloads?
8482
// assert(request.amount == msg.jettonAmount, TokenPool_Error.AmountMismatch);
@@ -107,29 +105,8 @@ fun onLockOrBurnTransfer(
107105
return st;
108106
}
109107

110-
var request = requestMsg.request.load();
111-
emit(TOKEN_POOL_LOCKED_OR_BURNED_TOPIC, TokenPool_LockedOrBurned {
112-
remoteChainSelector: request.remoteChainSelector,
113-
details: TokenPool_LockedOrBurnedDetails {
114-
token: request.localToken,
115-
sender: msg.transferInitiator!,
116-
amount: prepared.destTokenAmount,
117-
}.toCell(),
118-
});
119-
120-
// TODO: we should reply in any case, send a message to the OnRamp to indicate that the lockOrBurn was processed
121-
if (requestMsg.replyTo != null) {
122-
createMessage({
123-
bounce: true,
124-
value: 0,
125-
dest: requestMsg.replyTo!,
126-
body: TokenPool_LockOrBurnResponse {
127-
queryId: requestMsg.queryId,
128-
out: prepared.out.toCell(),
129-
destTokenAmount: prepared.destTokenAmount,
130-
},
131-
}).send(SEND_MODE_CARRY_ALL_REMAINING_MESSAGE_VALUE);
132-
}
108+
var pool = loadPool(st);
109+
pool.onLockOrBurnTransferFinalize(fwdp);
133110

134111
return st;
135112
}
@@ -207,7 +184,7 @@ fun onReturnExcessesBack(
207184
bounce: true,
208185
value: LockReleaseTokenPool_REPLY_VALUE,
209186
dest: pending.replyTo!,
210-
body: TokenPool_ReleaseOrMintResponse {
187+
body: TokenPool_ReleaseOrMintFinished {
211188
queryId: msg.queryId,
212189
out: pending.out,
213190
},

contracts/contracts/ccip/pools/lock_release_token_pool/events.tolk

Lines changed: 0 additions & 39 deletions
This file was deleted.

contracts/contracts/ccip/pools/lock_release_token_pool/types.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const LockReleaseTokenPool_RELEASE_TRANSFER_VALUE = ton("0.05");
88
const LockReleaseTokenPool_REPLY_VALUE = ton("0.01");
99

1010
struct LockReleaseTokenPool_PendingRelease {
11-
replyTo: address? = null;
11+
replyTo: address?;
1212
request: Cell<TokenPool_ReleaseOrMintInV1>;
1313
out: Cell<TokenPool_ReleaseOrMintOutV1>;
1414
expectedSender: address;

contracts/contracts/ccip/pools/messages.tolk

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ struct (0xfa7da444) TokenPool_LockOrBurnWithdraw {
110110
request: Cell<TokenPool_LockOrBurnInV1>; // TODO: consider renaming
111111
}
112112

113-
struct (0x6c060424) TokenPool_LockOrBurnResponse {
113+
struct (0x6c060424) TokenPool_LockOrBurnFinished {
114114
queryId: uint64;
115115
// TODO: unwrap and inline this type
116116
out: Cell<TokenPool_LockOrBurnOutV1>;
117117
destTokenAmount: uint256;
118118
}
119119

120-
struct (0x78dc2232) TokenPool_ReleaseOrMintResponse {
120+
struct (0x78dc2232) TokenPool_ReleaseOrMintFinished {
121121
queryId: uint64;
122122
out: Cell<TokenPool_ReleaseOrMintOutV1>;
123123
}
@@ -129,6 +129,6 @@ struct (0xef0cb36e) TokenPool_ReleaseOrMintFailure {
129129

130130
type TokenPool_OutMessage =
131131
| TokenPool_LockOrBurnWithdraw
132-
| TokenPool_LockOrBurnResponse
133-
| TokenPool_ReleaseOrMintResponse
134-
| TokenPool_ReleaseOrMintFailure;
132+
| TokenPool_LockOrBurnFinished
133+
| TokenPool_ReleaseOrMintFinished
134+
| TokenPool_ReleaseOrMintFailure;

contracts/contracts/ccip/pools/token_pool.tolk

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,6 @@ fun TokenPool<T>.validateLockOrBurn(
639639
self.preflightCheck(request, requestedFinalityConfig, tokenArgs, destTokenAmount);
640640

641641
return TokenPool_LockOrBurnPrepared {
642-
request: request.toCell(),
643-
requestedFinalityConfig,
644-
tokenArgs,
645642
feeAmount,
646643
destTokenAmount,
647644
usingFastFinality,
@@ -713,8 +710,41 @@ fun TokenPool<T>.onLockOrBurnTransfer(
713710
if (self.hooks != null && self.hooks.onLockOrBurnTransfer != null) {
714711
self.context = self.hooks.onLockOrBurnTransfer(self.context!, sender, msg);
715712
}
713+
714+
// TODO:
716715
}
717716

717+
fun TokenPool<T>.onLockOrBurnTransferFinalize(
718+
mutate self,
719+
fwdPayload: TokenPool_LockOrBurnForwardPayload,
720+
): void {
721+
val requestMsg = lazy fwdPayload.requestMsg.load();
722+
val prepared = lazy fwdPayload.prepared.load();
723+
724+
var request = requestMsg.request.load();
725+
emit(TOKEN_POOL_LOCKED_OR_BURNED_TOPIC, TokenPool_LockedOrBurned {
726+
remoteChainSelector: request.remoteChainSelector,
727+
details: TokenPool_LockedOrBurnedDetails {
728+
token: request.localToken,
729+
sender: request.originalSender,
730+
amount: prepared.destTokenAmount,
731+
}.toCell(),
732+
});
733+
734+
// TODO: we should reply in any case, send a message to the OnRamp to indicate that the lockOrBurn was processed
735+
if (requestMsg.replyTo != null) {
736+
createMessage({
737+
bounce: true,
738+
value: 0,
739+
dest: requestMsg.replyTo!,
740+
body: TokenPool_LockOrBurnFinished {
741+
queryId: requestMsg.queryId,
742+
out: prepared.out.toCell(),
743+
destTokenAmount: prepared.destTokenAmount,
744+
},
745+
}).send(SEND_MODE_CARRY_ALL_REMAINING_MESSAGE_VALUE);
746+
}
747+
}
718748

719749
// function lockOrBurn(
720750
// Pool.LockOrBurnInV1 calldata lockOrBurnIn,

contracts/contracts/ccip/pools/token_pool_contract.tolk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ contract TokenPool {
1818
// TODO: should be used in hooks of the core library,
1919
// but for now we need to register them here.
2020
forceAbiExport: TokenPool_LockOrBurn
21-
| TokenPool_LockOrBurnResponse
22-
| TokenPool_ReleaseOrMintResponse
21+
| TokenPool_LockOrBurnFinished
22+
| TokenPool_ReleaseOrMintFinished
2323
}
2424

2525
fun onInternalMessage(_: InMessage) {

contracts/contracts/ccip/pools/types.tolk

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ struct TokenPool_TokenTransferFeeConfigArgs {
7878
// TODO: triage new types below
7979

8080
struct TokenPool_LockOrBurnPrepared {
81-
request: Cell<TokenPool_LockOrBurnInV1>;
82-
requestedFinalityConfig: uint32;
83-
tokenArgs: cell?;
8481
feeAmount: uint256;
8582
destTokenAmount: uint256;
8683
usingFastFinality: bool;

0 commit comments

Comments
 (0)