Skip to content

Commit bd7740c

Browse files
integrate ocr3base with offramp (#73)
* add handler for SetOCR3BaseConfig * add transmit calls on the OffRamp * add ccip/OffRamp.ts tes * check that offRamp handles setOCR3Base message * fix broken ccipRouter test * handle setOCR3Config on functino on contract * refactor: move examples under test/ folder on contracts * fmt * fmt * use real feeQuoter * fmt * fix compilation bugs * fix compilation error * fmt * set commit and exec configs on offramp * rm mock fee quoter
1 parent b0da419 commit bd7740c

File tree

51 files changed

+407
-135
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+407
-135
lines changed

contracts/contracts/ccip/fee_quoter.tolk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ fun updatePrices(mutate st: Storage, priceUpdates: PriceUpdates) {
170170
value: update.usdPerToken,
171171
timestamp
172172
})
173+
//TODO: emit UsdPerTokenUpdated(update.sourceToken, update.usdPerToken, block.timestamp);
173174
}
174175

175176
var iter2 = Iterator<GasPriceUpdate>.new(priceUpdates.gasPriceUpdates);
@@ -186,6 +187,8 @@ fun updatePrices(mutate st: Storage, priceUpdates: PriceUpdates) {
186187
timestamp
187188
}.toCell();
188189
st.destChainConfigs.replace(update.destChainSelector, destChainConfig);
190+
191+
//TODO: emit UsdPerUnitGasUpdated(update.destChainSelector, update.usdPerUnitGas, block.timestamp);
189192
}
190193
}
191194

contracts/contracts/ccip/offramp.tolk

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ import "../lib/upgrades/type_and_version.tolk";
44
import "./../lib/merkle_multi_proof/merkle_multi_proof.tolk"
55
import "../deployable/types.tolk";
66
import "../lib/utils.tolk";
7+
import "../lib/ocr/multi_ocr3_base";
8+
import "../lib/ocr/types";
79

810
struct Storage {
911
ownable: Ownable2Step;
1012
deployer: cell; // Deployable compiled code
1113
merkleRootCode: cell; // make sure to use a library cell offchain to save space
1214
feeQuoter: address;
15+
ocr3Base: OCR3Base
1316

1417
// static config
1518
chainSelector: uint64;
1619
// dynamic config
1720
permissionlessExecutionThresholdSeconds: uint32,
1821

19-
// TODO: embed ocr3 base state
2022
sourceChainConfigs: UMap<uint64, SourceChainConfig>;
2123

2224
// This is the OCR sequence number, not to be confused with the CCIP message sequence number.
@@ -90,32 +92,40 @@ struct CommitReport {
9092
struct (0x00000001) Commit {
9193
queryId: uint64;
9294
// TODO: could just store as one slice since context is fixed size
93-
reportContext: cell;
94-
report: cell;
95+
reportContext: ReportContext;
96+
report: CommitReport;
9597
signatures: cell;
9698
}
9799

98100
struct (0x00000002) Execute {
99101
queryId: uint64;
100102
// TODO: could just store as one slice since context is fixed size
101-
reportContext: cell;
102-
report: cell;
103+
reportContext: ReportContext;
104+
report: ExecutionReport;
103105
}
104106

105-
type Msg = Commit | Execute;
107+
type Msg = Commit | Execute | OCR3Base_SetOCR3Config;
106108

107109
fun onInternalMessage(in:InMessage) {
108110
val msg = lazy Msg.fromSlice(in.body);
109111
match (msg) {
110112
Commit => { commit(msg, in.senderAddress) }
111113
Execute => { _execute(msg, in.senderAddress) }
114+
OCR3Base_SetOCR3Config => { _setOCR3Config(msg, in.senderAddress)}
112115
else => {
113116
// ignore empty messages, "wrong opcode" for others
114117
assert (in.body.isEmpty()) throw 0xFFFF
115118
}
116119
}
117120
}
118121

122+
fun _setOCR3Config(msg: OCR3Base_SetOCR3Config, sender: address) {
123+
var st = lazy Storage.load();
124+
st.ownable.requireOwner(sender);
125+
st.ocr3Base.setOcr3Config(msg);
126+
st.store();
127+
}
128+
119129
@pure @inline
120130
fun getMerkleRootID(merkleRoot: uint256): builder {
121131
return beginCell() // id:u16 = 1 | merkleRoot:256
@@ -125,22 +135,20 @@ fun getMerkleRootID(merkleRoot: uint256): builder {
125135
}
126136

127137
fun commit(msg: Commit, sender: address) {
128-
val st = lazy Storage.load();
129-
130-
// ocr3 base: validate signatures
131-
132-
// parse report
133-
val report = CommitReport.fromCell(msg.report);
138+
var st = lazy Storage.load();
134139

135140
// TODO: verify RMN signatures on blessed roots
141+
val report = msg.report;
136142

137143
// update token/gas prices if any
138144
if (report.priceUpdates != null) {
139145
val updatePricesMsg = createMessage({
140146
bounce: true, // TODO:
141147
value: ton("0.05"), // TODO:
142148
dest: st.feeQuoter,
143-
body: report.priceUpdates!.load(),
149+
body: UpdatePrices{
150+
updates: report.priceUpdates!.load()
151+
},
144152
});
145153
updatePricesMsg.send(SEND_MODE_REGULAR);
146154
}
@@ -191,6 +199,15 @@ fun commit(msg: Commit, sender: address) {
191199
initMsg.send(SEND_MODE_REGULAR);
192200
}
193201

202+
// Verifies signatures and emits Transmitted event
203+
st.ocr3Base.transmit(
204+
sender,
205+
OCR_PLUGIN_TYPE_COMMIT,
206+
msg.reportContext,
207+
report.toCell(),
208+
msg.signatures
209+
);
210+
194211
emit(CCIP_COMMIT_REPORT_ACCEPTED_TOPIC, CommitReportAccepted {
195212
priceUpdates: report.priceUpdates,
196213
blessedMerkleRoots: report.blessedMerkleRoots,
@@ -199,15 +216,13 @@ fun commit(msg: Commit, sender: address) {
199216
}
200217

201218
fun _execute(msg: Execute, sender: address) {
202-
val st = lazy Storage.load();
219+
var st = lazy Storage.load();
203220

204221
// ocr3 base: validate execute report
205222

206223
// TODO: manual execution flag
207224
// TODO: check if chain was cursed by RMNRemote
208-
209-
// parse report
210-
val report = ExecutionReport.fromCell(msg.report);
225+
val report = msg.report;
211226

212227
var messages = Iterator<Any2TVMRampMessage>.new(report.messages);
213228

@@ -279,6 +294,14 @@ fun _execute(msg: Execute, sender: address) {
279294
// executeMsg.send(SEND_MODE_REGULAR);
280295

281296
// TODO: how do we handle incrementing the nonce? since execution is async this might take a while
297+
298+
st.ocr3Base.transmit(
299+
sender,
300+
OCR_PLUGIN_TYPE_EXECUTE,
301+
msg.reportContext,
302+
msg.report.toCell(),
303+
beginCell().endCell(),
304+
);
282305
}
283306

284307
// TODO: handle signals from MerkleRoot (release tokens, execute)

contracts/contracts/lib/ocr/multi_ocr3_base.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct (0x2B78359F) OCR3Base_SetOCR3Config {
5151
}
5252

5353
struct OCR3Base {
54-
chainId: uint8;
54+
chainId: uint8; //TODO :Is this even necessary?
5555
commit: Cell<Config>?;
5656
execute: Cell<Config>?;
5757
}

contracts/contracts/examples/async-communication/request-reply-with-two-dependencies/inventory.tact renamed to contracts/contracts/test/examples/async-communication/request-reply-with-two-dependencies/inventory.tact

File renamed without changes.

contracts/contracts/examples/async-communication/request-reply-with-two-dependencies/item_count.tact renamed to contracts/contracts/test/examples/async-communication/request-reply-with-two-dependencies/item_count.tact

File renamed without changes.

contracts/contracts/examples/async-communication/request-reply-with-two-dependencies/item_price.tact renamed to contracts/contracts/test/examples/async-communication/request-reply-with-two-dependencies/item_price.tact

File renamed without changes.

contracts/contracts/examples/async-communication/request-reply-with-two-dependencies/storage.tact renamed to contracts/contracts/test/examples/async-communication/request-reply-with-two-dependencies/storage.tact

File renamed without changes.

contracts/contracts/examples/async-communication/request-reply/item_price.tact renamed to contracts/contracts/test/examples/async-communication/request-reply/item_price.tact

File renamed without changes.

contracts/contracts/examples/async-communication/request-reply/price_registry.tact renamed to contracts/contracts/test/examples/async-communication/request-reply/price_registry.tact

File renamed without changes.

contracts/contracts/examples/async-communication/request-reply/storage.tact renamed to contracts/contracts/test/examples/async-communication/request-reply/storage.tact

File renamed without changes.

0 commit comments

Comments
 (0)