Skip to content

Commit

Permalink
Refactor contract to include manifestUrl getter and update staticTaxFee
Browse files Browse the repository at this point in the history
  • Loading branch information
Laisky committed Sep 10, 2024
1 parent 7ca08e1 commit 6cb60e4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
56 changes: 30 additions & 26 deletions blockchain/ton/contracts/attest/contracts/attest.tact
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ contract Attest with Common {

let jettonMaster = initOf JettonMaster(
myAddress(),
"https://ario.laisky.com/SYDesz5IAu3jeEn4RnxaVQQLRk1q-nx13Z4A4OuiUzI",
"https://s3.laisky.com/uploads/2024/09/jetton-attest.json",
);

self.reserveValue(0);
Expand All @@ -196,6 +196,8 @@ contract Attest with Common {
forwardTonAmount: 0,
response_destination: msg.response_destination,
}.toCell(),
code: jettonMaster.code,
data: jettonMaster.data,
});
}

Expand Down Expand Up @@ -297,8 +299,26 @@ contract Bot with Common {
nativeThrowUnless(codeBalanceNotSufficient, myBalance() >= self.lockedValue + msg.attestValue);
nativeThrowUnless(codeAttestValueNotSufficient, msg.attestValue >= MinimalAttestValue);

self.attestTaskId = self.attestTaskId + 1;

// save the incentive of the task
self.attestTaskIncentives.set(self.attestTaskId, PendingAttestTask{
incentive: msg.attestValue,
finishedNotifyUser: msg.finishedNotifyUser,
finishedNotifyAmount: msg.finishedNotifyAmount,
finishedNotifyMessage: msg.finishedNotifyMessage,
});

// lock the incentive of the task for the verifier
let increasedLockedValue = msg.attestValue;
if (msg.finishedNotifyUser != null) {
nativeThrowUnless(codeFinishedNotifyFieldsInvalid, msg.finishedNotifyAmount != null);
nativeThrowUnless(codeInflowValueNotSufficient, ctx.value >= increasedLockedValue);
increasedLockedValue = increasedLockedValue + msg.finishedNotifyAmount!!;
}

// forward the task to the master contract
self.reserveValue(msg.attestValue);
self.reserveValue(increasedLockedValue);
send(SendParameters{
to: self.master,
value: 0,
Expand All @@ -315,23 +335,7 @@ contract Bot with Common {
}
);

self.attestTaskId = self.attestTaskId + 1;

// save the incentive of the task
self.attestTaskIncentives.set(self.attestTaskId, PendingAttestTask{
incentive: msg.attestValue,
finishedNotifyUser: msg.finishedNotifyUser,
finishedNotifyTonAmound: msg.finishedNotifyTonAmound,
finishedNotifyMessage: msg.finishedNotifyMessage,
});

// lock the incentive of the task for the verifier
self.lockedValue = self.lockedValue + msg.attestValue;
if (msg.finishedNotifyUser != null) {
nativeThrowUnless(codeFinishedNotifyFieldsInvalid, msg.finishedNotifyTonAmound != null);
nativeThrowUnless(codeFinishedNotifyFieldsInvalid, msg.finishedNotifyMessage != null);
self.lockedValue = self.lockedValue + msg.finishedNotifyTonAmound!!;
}
self.lockedValue = self.lockedValue + increasedLockedValue;
}

// verifier contract will submit the attest task result by
Expand All @@ -355,12 +359,12 @@ contract Bot with Common {
}

let ctx = context();
let oracle = initOf Oracle(self.master, msg.oracleOwner);
let oracleAddr = contractAddress(oracle);

// sender must be an oracle contract
let incentive = task!!.incentive;
let balanceReduced: Int = incentive;

// sender must be an oracle contract
let oracle = initOf Oracle(self.master, msg.oracleOwner);
let oracleAddr = contractAddress(oracle);
nativeThrowUnless(codeSenderAddressInvalid, oracleAddr == sender());
nativeThrowUnless(codeBalanceNotSufficient, myBalance() - ctx.value - incentive >= 0);

Expand All @@ -386,13 +390,13 @@ contract Bot with Common {

// notify users
if (task!!.finishedNotifyUser != null) {
let amount = task!!.finishedNotifyTonAmound!!;
balanceReduced = balanceReduced + amount;
balanceReduced = balanceReduced + task!!.finishedNotifyAmount!!;
nativeThrowUnless(codeBalanceNotSufficient, myBalance() - ctx.value - balanceReduced >= 0);

// mint token to the user
send(SendParameters{
to: self.master,
value: amount,
value: task!!.finishedNotifyAmount!!,
bounce: false,
body: NotifyUser{
queryId: msg.queryId,
Expand Down
8 changes: 4 additions & 4 deletions blockchain/ton/contracts/attest/contracts/messages.tact
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ message(0x98d245a0) SubmitAttestTask {
attestValue: Int;
// if finishedNotifyUser is not null, notify user when the attest task is finished.
finishedNotifyUser: Address?;
// finishedNotifyTonAmound should not be null when finishedNotifyUser is not null.
finishedNotifyTonAmound: Int? as coins;
// finishedNotifyAmount should not be null when finishedNotifyUser is not null.
finishedNotifyAmount: Int? as coins;
// finishedNotifyMessage should not be null when finishedNotifyUser is not null.
finishedNotifyMessage: String?;
}
Expand Down Expand Up @@ -128,8 +128,8 @@ struct PendingAttestTask {
incentive: Int as coins;
// if finishedNotifyUser is not null, notify user when the attest task is finished.
finishedNotifyUser: Address?;
// finishedNotifyTonAmound should not be null when finishedNotifyUser is not null.
finishedNotifyTonAmound: Int? as coins;
// finishedNotifyAmount should not be null when finishedNotifyUser is not null.
finishedNotifyAmount: Int? as coins;
// finishedNotifyMessage should not be null when finishedNotifyUser is not null.
finishedNotifyMessage: String?;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export async function run(provider: NetworkProvider) {
queryId: BigInt("123"),
proofUrl: "https://ario.laisky.com/alias/attest-proof.json",
attestValue: toNano("0.1"),
finishedNotifyUser: provider.sender().address!!,
finishedNotifyTonAmount: toNano("0.1"),
finishedNotifyMessage: "task finished",
}
);
}

0 comments on commit 6cb60e4

Please sign in to comment.