Skip to content

Commit 56a41ec

Browse files
committed
Cleanup TokenPool<T>.onReleaseOrMint hook
1 parent 528d375 commit 56a41ec

5 files changed

Lines changed: 21 additions & 24 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,14 @@ fun loadPool(st: Storage): TokenPool<Storage> {
212212
ensureOutboundAccess: null,
213213
ensureInboundAccess: null,
214214
ensureNotCursed: null,
215-
preflightCheck: null,
215+
onReleaseOrMint: null,
216+
handleReleaseOrMintMessage,
216217
postflightCheck: null,
217-
applyLockOrBurn: null,
218-
applyReleaseOrMint: null,
219218
onLockOrBurn: null,
220219
validateLockOrBurn: null,
220+
preflightCheck: null,
221221
onLockOrBurnTransfer: null,
222222
onLockOrBurnTransferContinue,
223-
handleReleaseOrMintMessage,
224223
},
225224
};
226225
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,14 @@ fun loadPool(st: Storage): TokenPool<Storage> {
182182
ensureOutboundAccess: null,
183183
ensureInboundAccess: null,
184184
ensureNotCursed: null,
185-
preflightCheck: null,
185+
onReleaseOrMint: null,
186186
postflightCheck: null,
187-
applyLockOrBurn: null,
188-
applyReleaseOrMint: null,
187+
handleReleaseOrMintMessage,
189188
onLockOrBurn: null,
190189
validateLockOrBurn: null,
190+
preflightCheck: null,
191191
onLockOrBurnTransfer: null,
192192
onLockOrBurnTransferContinue: null,
193-
handleReleaseOrMintMessage,
194193
},
195194
};
196195
}

contracts/contracts/ccip/pools/token_pool.tolk

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ struct TokenPool_Hooks<T> {
4848
ensureOutboundAccess: ((T?, address, uint64) -> void)?;
4949
ensureInboundAccess: ((T?, address, uint64) -> void)?;
5050
ensureNotCursed: ((T?, uint64) -> void)?;
51-
applyLockOrBurn: ((T?, TokenPool_LockOrBurnPrepared) -> void)?;
52-
applyReleaseOrMint: ((T?, TokenPool_ReleaseOrMintPrepared) -> void)?;
5351

5452
// ReleaseOrMint flow
53+
onReleaseOrMint: ((T, TokenPool_ReleaseOrMint) -> T)?;
5554
postflightCheck: ((T?, TokenPool_ReleaseOrMintInV1, uint256, uint32) -> bool)?;
5655
handleReleaseOrMintMessage: ((T?, address, TokenPool_ReleaseOrMint, TokenPool_ReleaseOrMintPrepared) -> T?)?;
5756

@@ -464,13 +463,10 @@ fun TokenPool<T>.onInternalMessage(mutate self, msgSender: address, msgValue: co
464463
//
465464
// In the worst case, not enough funds, received Jettons are burned.
466465
TransferNotificationForRecipient => {
467-
// TODO: how do we know this transfer is allowed - easiest to just accept transfers from the Router (static)
468466
self.onLockOrBurnTransfer(msgSender, msg);
469467
}
470468
TokenPool_ReleaseOrMint => {
471-
val (_wait, prepared) = self.validateReleaseOrMint(msgSender, msg.request.load(), msg.requestedFinalityConfig);
472-
assert(self.hooks != null && self.hooks.handleReleaseOrMintMessage != null, TokenPool_Error.UnsupportedOperation);
473-
self.context = self.hooks.handleReleaseOrMintMessage(self.context, msgSender, msg, prepared);
469+
self.onReleaseOrMint(msgSender, msg);
474470
}
475471
TokenPool_PostflightCheckFinished => {
476472
// TODO: implement me
@@ -871,17 +867,20 @@ fun TokenPool<T>.validateReleaseOrMint(
871867
});
872868
}
873869

874-
fun TokenPool<T>.releaseOrMint(
870+
fun TokenPool<T>.onReleaseOrMint(
875871
mutate self,
876872
sender: address,
877-
request: TokenPool_ReleaseOrMintInV1,
878-
requestedFinalityConfig: uint32 = TOKEN_POOL_DEFAULT_FINALITY,
879-
): TokenPool_ReleaseOrMintPrepared {
880-
val (_wait, prepared) = self.validateReleaseOrMint(sender, request, requestedFinalityConfig);
881-
if (self.hooks != null && self.hooks.applyReleaseOrMint != null) {
882-
self.hooks.applyReleaseOrMint(self.context, prepared);
873+
msg: TokenPool_ReleaseOrMint,
874+
): void {
875+
if (self.hooks != null && self.hooks.onReleaseOrMint != null) {
876+
self.context = self.hooks.onReleaseOrMint(self.context!, msg);
877+
}
878+
879+
val (_wait, prepared) = self.validateReleaseOrMint(sender, msg.request.load(), msg.requestedFinalityConfig);
880+
// TODO: move to specific fn call
881+
if (self.hooks != null && self.hooks.handleReleaseOrMintMessage != null) {
882+
self.context = self.hooks.handleReleaseOrMintMessage(self.context, sender, msg, prepared);
883883
}
884-
return prepared;
885884
}
886885

887886
fun TokenPool<T>.encodeLocalDecimals(self): cell {

0 commit comments

Comments
 (0)