Skip to content

Commit

Permalink
Refactor contract to refund rest value when task id is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Laisky committed Sep 10, 2024
1 parent ed7eeac commit f82b409
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
40 changes: 20 additions & 20 deletions blockchain/ton/contracts/attest/contracts/attest.tact
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,21 @@ contract Bot with Common {
// this message, and the incentive will be sent to the verifier.
receive(msg: AttestTaskResult) {
let incentive = self.attestTaskIncentives.get(msg.taskId);
nativeThrowUnless(codeAttestTaskNotFound, incentive != null);
if (incentive == null) {
// task id not found, refund the rest value to the sender
self.reserveValue(0);
send(SendParameters{
to: msg.oracleOwner,
value: 0,
mode: SendRemainingBalance,
bounce: false,
body: Excesses{
queryId: msg.queryId,
}.toCell()
}
);
return;
}

let ctx = context();
let oracle = initOf Oracle(self.master, msg.oracleOwner);
Expand Down Expand Up @@ -471,7 +485,7 @@ contract Oracle with Common {
value: ton("0"),
bounce: false,
body: msg.toCell(),
mode: SendRemainingValue
mode: SendRemainingBalance,
}
);
}
Expand All @@ -481,25 +495,11 @@ contract Oracle with Common {
// until the release time.
receive(msg: PayAttestIncentive){
let ctx = context();
let bot = initOf Bot(self.master, msg.botOwner);
let botAddr = contractAddress(bot);

// sender must be the bot contract
nativeThrowUnless(codeSenderAddressInvalid, botAddr == sender());
nativeThrowUnless(codeInflowValueNotSufficient, ctx.value >= msg.incentive);

// refund the rest value to the bot
self.reserveValue(msg.incentive);
send(SendParameters{
to: sender(),
value: 0,
mode: SendRemainingBalance,
bounce: false,
body: Excesses{
queryId: msg.queryId,
}.toCell()
}
);
// sender should be the bot contract
// let bot = initOf Bot(self.master, msg.botOwner);
// let botAddr = contractAddress(bot);
// nativeThrowUnless(codeSenderAddressInvalid, botAddr == sender());

// if the release time is greater than now, lock the incentive.
// otherwise, refund the rest value to the bot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function run(provider: NetworkProvider) {
$$type: 'SubmitAttestTask',
queryId: BigInt("123"),
proofUrl: "https://ario.laisky.com/alias/attest-proof.json",
attestValue: toNano("0.01"),
attestValue: toNano("0.1"),
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export async function run(provider: NetworkProvider) {
await oracleContract.send(
provider.sender(),
{
value: toNano('0.1'),
value: toNano('1'),
},
{
$$type: 'AttestTaskResult',
queryId: BigInt("123"),
taskId: BigInt("0"),
taskId: BigInt("1"),
status: "verified",
verifiedUrl: "https://ario.laisky.com/alias/attest-verified.json",
botOwner: provider.sender().address!!,
Expand Down
4 changes: 2 additions & 2 deletions blockchain/ton/contracts/attest/scripts/oracle_register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export async function run(provider: NetworkProvider) {
await masterContract.send(
provider.sender(),
{
value: toNano('0.1'),
value: toNano('1'),
},
{
$$type: "RegisterOracle",
queryId: BigInt("123"),
stakeValue: toNano("0.05"), // should bigger than MinimalOracleStakeValue
stakeValue: toNano("0.01"), // should bigger than MinimalOracleStakeValue
oracleOwner: provider.sender().address!!,
responseDestination: provider.sender().address!!,
manifestUrl: "https://ario.laisky.com/alias/attest-manifest.json",
Expand Down
4 changes: 2 additions & 2 deletions blockchain/ton/contracts/attest/scripts/oracle_withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export async function run(provider: NetworkProvider) {
await oracleContract.send(
provider.sender(),
{
value: toNano('0.1'),
value: toNano('1'),
},
'gather_incentive'
);

await oracleContract.send(
provider.sender(),
{
value: toNano('0.1'),
value: toNano('1'),
},
'withdraw'
);
Expand Down

0 comments on commit f82b409

Please sign in to comment.