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
12 changes: 11 additions & 1 deletion contracts/contracts/ccip/ccipsend_executor/contract.tolk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "../onramp/types"
import "../common/messages"
import "../../lib/utils"

const CONTRACT_VERSION = "0.0.3";
const CONTRACT_VERSION = "0.0.4";
const FACILITY_NAME = "com.chainlink.ton.ccip.CCIPSendExecutor";

fun onInternalMessage(in: InMessage) {
Expand Down Expand Up @@ -160,6 +160,16 @@ get fun typeAndVersion(): (slice, slice) {
return ("com.chainlink.ton.ccip.CCIPSendExecutor", CONTRACT_VERSION);
}

// Returns the current code of the contract.
get fun code(): cell {
return contract.getCode();
}

// Returns the sha256 hash of the current code of the contract.
get fun codeHash(): int {
return contract.getCode().hash();
}

get fun facilityId(): uint16 {
return getFacilityId(stringCrc32("com.chainlink.ton.ccip.CCIPSendExecutor"));
}
Expand Down
2 changes: 2 additions & 0 deletions contracts/contracts/ccip/ccipsend_executor/messages.tolk
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import "types"
import "storage"
import "../../lib/versioning/upgradeable"

import "../common/messages"
import "../onramp/messages"
Expand Down
17 changes: 16 additions & 1 deletion contracts/contracts/ccip/fee_quoter/contract.tolk
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import "../../deployable/types";
import "../../lib/utils";
import "../router/messages"
import "../ccipsend_executor/messages"
import "../../lib/versioning/upgradeable"

const CONTRACT_VERSION = "0.0.3";
const CONTRACT_VERSION = "0.0.4";
const FACILITY_NAME = "com.chainlink.ton.ccip.FeeQuoter";

fun onInternalMessage(in: InMessage) {
Expand Down Expand Up @@ -43,6 +44,14 @@ fun onInternalMessage(in: InMessage) {
st.store();
}
FeeQuoter_GetValidatedFee<cell> => { getValidatedFee(msg, in.senderAddress) }
Upgradeable_Upgrade => {
var st = lazy Storage.load();
st.ownable.requireOwner(in.senderAddress);
Upgradeable{
migrate: migrate,
version: version,
}.upgrade(msg);
}
else => {
// ignore empty messages, "wrong opcode" for others
assert (in.body.isEmpty()) throw 0xFFFF
Expand Down Expand Up @@ -523,3 +532,9 @@ get fun destChainSelectors(): tuple {
var d = st.destChainConfigs;
return keysLispList(d)!;
}

@method_id(1000)
fun migrate(storage: cell): cell { return beginCell().endCell(); }

@method_id(1001)
fun version(): slice { return CONTRACT_VERSION; }
4 changes: 3 additions & 1 deletion contracts/contracts/ccip/fee_quoter/messages.tolk
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import "types"
import "../router/messages"
import "../../lib/versioning/upgradeable"

type FeeQuoter_InMessage =
| FeeQuoter_UpdatePrices
| FeeQuoter_UpdateFeeTokens
| FeeQuoter_UpdateTokenTransferFeeConfigs
| FeeQuoter_UpdateDestChainConfigs
| FeeQuoter_GetValidatedFee<cell>; // marked as cell since we never attempt to load the metadata
| FeeQuoter_GetValidatedFee<cell> // marked as cell since we never attempt to load the metadata
| Upgradeable_Upgrade;

struct (0x20000001) FeeQuoter_UpdatePrices {
updates: PriceUpdates
Expand Down
23 changes: 21 additions & 2 deletions contracts/contracts/ccip/offramp/contract.tolk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "types"
import "storage"
import "events"

import "../../lib/versioning/upgradeable"
import "../common/types.tolk"
import "../../deployable/types.tolk"
import "../../lib/access/ownable_2step.tolk"
Expand All @@ -16,7 +17,7 @@ import "../merkle_root/messages"
import "../../lib/receiver/messages"
import "../merkle_root/storage"

const CONTRACT_VERSION = "0.0.3";
const CONTRACT_VERSION = "0.0.4";

fun onInternalMessage(in:InMessage) {
val msg = lazy OffRamp_InMessage.fromSlice(in.body);
Expand Down Expand Up @@ -45,6 +46,9 @@ fun onInternalMessage(in:InMessage) {
OffRamp_NotifyFailure => {
_notifyFailure(msg, in.senderAddress);
}
Upgradeable_Upgrade => {
_upgrade(msg, in.senderAddress);
}
else => {
// ignore empty messages, "wrong opcode" for others
assert (in.body.isEmpty()) throw 0xFFFF
Expand All @@ -62,7 +66,22 @@ fun onBouncedMessage(in: InMessageBounced) {
_bouncedCCIPReceive(msg.rootId, in.senderAddress);
}
}
}
}

fun _upgrade(msg: Upgradeable_Upgrade, sender: address) {
val st = Storage.load();
st.ownable.requireOwner(sender);
Upgradeable{
migrate: migrate,
version: version,
}.upgrade(msg);
}

@method_id(1000)
fun migrate(storage: cell): cell { return beginCell().endCell(); }

@method_id(1001)
fun version(): slice { return CONTRACT_VERSION; }

fun _bouncedCCIPReceive(rootId: uint224, sender: address) {
val st = Storage.load();
Expand Down
4 changes: 3 additions & 1 deletion contracts/contracts/ccip/offramp/messages.tolk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "../../lib/ocr/types.tolk"
import "../../lib/ocr/multi_ocr3_base.tolk"
import "../../lib/receiver/messages.tolk"
import "../common/types.tolk"
import "../../lib/versioning/upgradeable"

type OffRamp_InMessage =
| OffRamp_Commit
Expand All @@ -12,7 +13,8 @@ type OffRamp_InMessage =
| OCR3Base_SetOCR3Config
| OffRamp_CCIPReceiveConfirm
| OffRamp_NotifyFailure
| OffRamp_NotifySuccess;
| OffRamp_NotifySuccess
| Upgradeable_Upgrade;

type OffRamp_BouncedMessage = Receiver_CCIPReceive;

Expand Down
17 changes: 16 additions & 1 deletion contracts/contracts/ccip/onramp/contract.tolk
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import "../ccipsend_executor/messages"
import "../router/messages"
import "../../lib/jetton/messages"
import "../../lib/jetton/messages_extended"
import "../../lib/versioning/upgradeable"

const CONTRACT_VERSION = "0.0.3";
const CONTRACT_VERSION = "0.0.4";

fun onInternalMessage(in: InMessage) {
val msg = lazy OnRamp_InMessage.fromSlice(in.body);
Expand Down Expand Up @@ -47,6 +48,14 @@ fun onInternalMessage(in: InMessage) {
applyAllowlistUpdates(mutate st, msg.updates);
st.store();
}
Upgradeable_Upgrade => {
var st = lazy OnRamp_Storage.load();
st.ownable.requireOwner(in.senderAddress);
Upgradeable{
migrate: migrate,
version: version,
}.upgrade(msg);
}
else => {
// ignore empty messages, "wrong opcode" for others
assert (in.body.isEmpty()) throw 0xFFFF
Expand Down Expand Up @@ -345,3 +354,9 @@ get fun code(): cell {
get fun codeHash(): int {
return contract.getCode().hash();
}

@method_id(1000)
fun migrate(storage: cell): cell { return beginCell().endCell(); }

@method_id(1001)
fun version(): slice { return CONTRACT_VERSION; }
2 changes: 2 additions & 0 deletions contracts/contracts/ccip/onramp/messages.tolk
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "types"
import "../common/messages"
import "../router/messages"
import "../../lib/versioning/upgradeable"

type OnRamp_InMessage =
| OnRamp_Send
Expand All @@ -10,6 +11,7 @@ type OnRamp_InMessage =
| OnRamp_UpdateDestChainConfigs
| OnRamp_UpdateAllowlists
| Common_JettonTransferNotification
| Upgradeable_Upgrade
;
// TODO | UpdateExecutorCode

Expand Down
23 changes: 20 additions & 3 deletions contracts/contracts/ccip/router/contract.tolk
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import "messages"
import "storage"
import "errors"

import "../onramp/messages"
import "../onramp/types"
import "../common/types"
import "../common/messages"
import "../../lib/access/ownable_2step"
import "../../deployable/types"
import "../../lib/access/ownable_2step"
import "../../lib/utils"
import "../../lib/jetton/messages"
import "../../lib/jetton/messages_extended"
import "../../lib/versioning/upgradeable"

const CONTRACT_VERSION = "0.0.2";

const CONTRACT_VERSION = "0.0.4";

fun onInternalMessage(in: InMessage) {
val msg = lazy Msg.fromSlice(in.body);
match (msg) {
Router_SetRamps => {onSetRamps(msg, in.senderAddress)}
Router_CCIPSend => { onSend(msg, in.senderAddress) }
Common_JettonTransferNotification => { onTransferNotification(msg, in.senderAddress) }
Upgradeable_Upgrade => { onUpgrade(msg, in.senderAddress) }
else => {
// ignore empty messages, "wrong opcode" for others
assert (in.body.isEmpty()) throw 0xFFFF
Expand Down Expand Up @@ -108,6 +110,21 @@ fun ccipSend(msg: Router_CCIPSend, sender: address) {
sendMsg.send(SEND_MODE_CARRY_ALL_REMAINING_MESSAGE_VALUE);
}

fun onUpgrade(msg: Upgradeable_Upgrade, sender: address) {
var st = lazy Storage.load();
st.ownable.requireOwner(sender);
Upgradeable{
migrate: migrate,
version: version,
}.upgrade(msg);
}

@method_id(1000)
fun migrate(storage: cell): cell { return beginCell().endCell(); }

@method_id(1001)
fun version(): slice { return CONTRACT_VERSION; }

get fun typeAndVersion(): (slice, slice) {
return ("com.chainlink.ton.ccip.Router", CONTRACT_VERSION);
}
Expand Down
3 changes: 2 additions & 1 deletion contracts/contracts/ccip/router/messages.tolk
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import "../common/types.tolk"
import "../common/messages"
import "../../lib/versioning/upgradeable"

type Msg = Router_CCIPSend | Router_SetRamps | Common_JettonTransferNotification;
type Msg = Router_CCIPSend | Router_SetRamps | Common_JettonTransferNotification | Upgradeable_Upgrade;

// update multiple chain selectors in batch to the same onramp address
struct (0x10000001) Router_SetRamps {
Expand Down
14 changes: 11 additions & 3 deletions contracts/contracts/examples/counter.tolk
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
tolk 1.1

import "@stdlib/common.tolk"
import "../lib/upgrades/type_and_version.tolk"
import "../lib/utils.tolk"
import "../lib/access/ownable_2step.tolk"

Expand Down Expand Up @@ -157,6 +156,15 @@ get fun value(): int {

/// Gets the current type and version of the contract.
get fun typeAndVersion(): (slice, slice) {
return TypeAndVersion { typeStr: "com.chainlink.ton.examples.Counter", versionStr: CONTRACT_VERSION }
.typeAndVersion();
return ("com.chainlink.ton.examples.Counter", CONTRACT_VERSION)
}

// Returns the current code of the contract.
get fun code(): cell {
return contract.getCode();
}

// Returns the sha256 hash of the current code of the contract.
get fun codeHash(): int {
return contract.getCode().hash();
}
41 changes: 0 additions & 41 deletions contracts/contracts/lib/upgrades/type_and_version.tolk

This file was deleted.

Loading
Loading