Skip to content

Commit

Permalink
Optimize nativeReserve calls and update contract logic for better per…
Browse files Browse the repository at this point in the history
…formance
  • Loading branch information
Laisky committed Aug 26, 2024
1 parent 5669072 commit e35d2b0
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions blockchain/ton/contracts/attest/contracts/attest.tact
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,7 @@ contract Attest with Deployable, OwnableTransferable, Txable, Common {
// all remaining value will be sent to the bot contract.
receive(msg: RegisterBot){
let ctx = context();
nativeReserve(myBalance() - ctx.value, ReserveExact);

emit(ctx.value.toString().asComment());
require(ctx.value >= self.forwardFee + self.emitFee + self.staticTaxFee, "Value not enough");
nativeReserve(myBalance() - ctx.value + self.emitFee + self.staticTaxFee, ReserveExact);

msg.botOwner = sender();
emit(msg.toCell());
Expand All @@ -188,7 +185,8 @@ contract Attest with Deployable, OwnableTransferable, Txable, Common {
// deploy bot contract and send the manifest to the bot
send(SendParameters{
to: botAddr,
value: ctx.value - self.emitFee - self.staticTaxFee,
value: 0,
mode: SendRemainingBalance,
bounce: false,
body: SetBotManifest{
nonce: 0,
Expand All @@ -204,9 +202,7 @@ contract Attest with Deployable, OwnableTransferable, Txable, Common {
// all remaining value will be sent to the oracle contract.
receive(msg: RegisterOracle){
let ctx = context();
nativeReserve(myBalance() - ctx.value, ReserveExact);

require(ctx.value >= self.forwardFee + self.emitFee + self.staticTaxFee + MinimalOraclePledgeValue, "Value not enough");
nativeReserve(myBalance() - ctx.value + self.emitFee + self.staticTaxFee, ReserveExact);

msg.oracleOwner = sender();
emit(msg.toCell());
Expand All @@ -217,7 +213,8 @@ contract Attest with Deployable, OwnableTransferable, Txable, Common {
// deploy oracle contract
send(SendParameters{
to: oracleAddr,
value: ctx.value - self.emitFee - self.staticTaxFee,
value: 0,
mode: SendRemainingBalance,
bounce: false,
code: oracle.code,
data: oracle.data
Expand All @@ -228,7 +225,7 @@ contract Attest with Deployable, OwnableTransferable, Txable, Common {
// publish attest task
receive(msg: PublishAttestTask){
let ctx = context();
nativeReserve(myBalance() - ctx.value, ReserveExact);
nativeReserve(myBalance() - ctx.value + self.emitFee + self.staticTaxFee, ReserveExact);

// verify sender is the owner of the bot
let bot = self.getBot(msg.botOwner);
Expand All @@ -246,7 +243,8 @@ contract Attest with Deployable, OwnableTransferable, Txable, Common {
// refund the rest value to the bot
send(SendParameters{
to: botAddr,
value: ctx.value - self.emitFee - self.staticTaxFee,
value: 0,
mode: SendRemainingBalance,
bounce: false,
body: "PublishAttestTask".asComment()
}
Expand Down Expand Up @@ -298,7 +296,7 @@ contract Bot with Ownable, Common {
// submit attest task
receive(msg: SubmitAttestTask){
let ctx = context();
nativeReserve(myBalance() - ctx.value, ReserveExact);
nativeReserve(myBalance() - ctx.value + msg.attestValue, ReserveExact);

self.requireOwner();
require(self.manifestUrl != "", "Manifest not set");
Expand All @@ -325,7 +323,8 @@ contract Bot with Ownable, Common {
};
send(SendParameters{
to: self.master,
value: ctx.value - msg.attestValue,
value: 0,
mode: SendRemainingBalance,
bounce: false,
body: pubMsg.toCell()
}
Expand All @@ -339,7 +338,7 @@ contract Bot with Ownable, Common {

let ctx = context();
// myBalance() - ctx.value - incentive!! must be non-negative
nativeReserve(myBalance() - ctx.value - incentive!!, ReserveExact);
nativeReserve(myBalance() - ctx.value - incentive!! + self.emitFee, ReserveExact);

// sender must be oracle contract
let oracle = initOf Oracle(self.master, msg.oracleOwner);
Expand All @@ -351,7 +350,8 @@ contract Bot with Ownable, Common {
// send the incentive to the verifier
send(SendParameters{
to: sender(),
value: ctx.value + incentive!! - self.emitFee,
value: 0,
mode: SendRemainingBalance,
bounce: false,
}
);
Expand Down

0 comments on commit e35d2b0

Please sign in to comment.