Skip to content

Commit b0a18ca

Browse files
authored
set custom liveness and bond at propose time (#105)
* set custom liveness and bond at propose time Signed-off-by: Gerhard Steenkamp <gerhard@umaproject.org> * test custom bond set at proposal time Signed-off-by: Gerhard Steenkamp <gerhard@umaproject.org> * update deployments in readme Signed-off-by: Gerhard Steenkamp <gerhard@umaproject.org> --------- Signed-off-by: Gerhard Steenkamp <gerhard@umaproject.org>
1 parent c2380b6 commit b0a18ca

4 files changed

Lines changed: 190 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ This subgraph indexes events and function calls by the "Managed Optimistic Oracl
146146

147147
- Amoy
148148
- TheGraph:
149-
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/amoy-managed-optimistic-oracle-v2/1.0.3/gn>
149+
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/amoy-managed-optimistic-oracle-v2/1.0.5/gn>
150150
- Polygon
151151
- TheGraph:
152-
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/polygon-managed-optimistic-oracle-v2/1.0.1/gn>
152+
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/polygon-managed-optimistic-oracle-v2/1.0.2/gn>
153153

154154
## Financial Contract Events
155155

packages/managed-oracle-v2/src/mappings/optimisticOracleV2.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,27 @@ export function handleOptimisticProposePrice(event: ProposePrice): void {
186186
event.params.ancillaryData
187187
);
188188

189+
// Look up custom bond and liveness values that may have been set before the request
190+
let customBond = getCustomBond(event.params.requester, event.params.identifier, event.params.ancillaryData);
191+
if (customBond !== null) {
192+
const bond = customBond.customBond;
193+
const currency = customBond.currency;
194+
log.debug("custom bond of {} of currency {} was set for request Id: {}", [
195+
bond.toString(),
196+
currency.toHexString(),
197+
requestId,
198+
]);
199+
request.bond = bond;
200+
request.currency = currency;
201+
}
202+
203+
let customLiveness = getCustomLiveness(event.params.requester, event.params.identifier, event.params.ancillaryData);
204+
if (customLiveness !== null) {
205+
const liveness = customLiveness.customLiveness;
206+
log.debug("custom liveness of {} was set for request Id: {}", [liveness.toString(), requestId]);
207+
request.customLiveness = customLiveness.customLiveness;
208+
}
209+
189210
request.save();
190211
}
191212

packages/managed-oracle-v2/tests/managed-oracle-v2/managedOracle.test.ts

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { describe, test, clearStore, afterAll, assert, log, afterEach } from "matchstick-as/assembly/index";
22
import { handleCustomLivenessSet, handleCustomBondSet } from "../../src/mappings/managedOracleV2";
3-
import { handleOptimisticRequestPrice } from "../../src/mappings/optimisticOracleV2";
3+
import { handleOptimisticProposePrice, handleOptimisticRequestPrice } from "../../src/mappings/optimisticOracleV2";
44
import {
55
createCustomLivenessSetEvent,
66
createCustomBondSetEvent,
7+
createProposePriceEvent,
78
createRequestPriceEvent,
89
mockGetState,
910
State,
@@ -26,6 +27,9 @@ namespace Constants {
2627
export const reward = 1000000;
2728
export const finalFee = 500000;
2829
export const timestamp = 1757284669;
30+
export const customLiveness_2 = 123456;
31+
export const customBond_2 = 3000000;
32+
export const currency_2 = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48";
2933
}
3034

3135
describe("Managed OOv2", () => {
@@ -120,7 +124,7 @@ describe("Managed OOv2", () => {
120124
log.info("Custom Bond: {}", [customBondEntity.customBond.toString()]);
121125
});
122126

123-
test("Custom bond and liveness are applied to RequestPrice entity", () => {
127+
test("Custom bond and liveness are applied to RequestPrice entity at REQUEST time", () => {
124128
mockGetState(
125129
Constants.requester,
126130
Constants.identifierHex,
@@ -210,6 +214,108 @@ describe("Managed OOv2", () => {
210214
log.info("Created OptimisticPriceRequest entity: {}", [priceRequestEntity.id]);
211215
log.info("Custom Liveness: {}", [priceRequestEntity.customLiveness!.toString()]);
212216
log.info("Custom Bond: {}", [priceRequestEntity.bond!.toString()]);
217+
log.info("Custom Bond Currency: {}", [priceRequestEntity.currency!.toHexString()]);
213218
log.info("State: {}", [priceRequestEntity.state!]);
214219
});
220+
221+
test("Custom bond and liveness are applied to RequestPrice entity at PROPOSE time", () => {
222+
mockGetState(
223+
Constants.requester,
224+
Constants.identifierHex,
225+
Constants.timestamp,
226+
Constants.ancillaryData,
227+
State.Requested
228+
);
229+
// Step 1: Create RequestPrice event
230+
const requestPriceEvent = createRequestPriceEvent(
231+
Constants.requester,
232+
Constants.identifierHex,
233+
Constants.timestamp,
234+
Constants.ancillaryData,
235+
Constants.currency,
236+
Constants.reward,
237+
Constants.finalFee
238+
);
239+
handleOptimisticRequestPrice(requestPriceEvent);
240+
241+
// Step 2: Set custom liveness
242+
const customLivenessEvent = createCustomLivenessSetEvent(
243+
Constants.managedRequestId,
244+
Constants.requester,
245+
Constants.identifierHex,
246+
Constants.ancillaryData,
247+
Constants.customLiveness
248+
);
249+
handleCustomLivenessSet(customLivenessEvent);
250+
// Step 3: Set custom bond
251+
const customBondEvent = createCustomBondSetEvent(
252+
Constants.managedRequestId,
253+
Constants.requester,
254+
Constants.identifierHex,
255+
Constants.ancillaryData,
256+
Constants.currency_2,
257+
Constants.customBond_2
258+
);
259+
handleCustomBondSet(customBondEvent);
260+
261+
mockGetState(
262+
Constants.requester,
263+
Constants.identifierHex,
264+
Constants.timestamp,
265+
Constants.ancillaryData,
266+
State.Proposed
267+
);
268+
269+
// Step 4: Create ProposePrice event
270+
const proposePriceEvent = createProposePriceEvent(
271+
Constants.requester,
272+
Constants.requester,
273+
Constants.identifierHex,
274+
Constants.timestamp,
275+
Constants.ancillaryData,
276+
1,
277+
Constants.timestamp + 3600,
278+
Constants.currency
279+
);
280+
handleOptimisticProposePrice(proposePriceEvent);
281+
282+
const requestId = Constants.identifierString
283+
.concat("-")
284+
.concat(Constants.timestamp.toString())
285+
.concat("-")
286+
.concat(Constants.ancillaryData);
287+
288+
const priceRequestEntity = OptimisticPriceRequest.load(requestId);
289+
290+
assert.assertTrue(priceRequestEntity !== null, "OptimisticPriceRequest entity should be created");
291+
292+
if (priceRequestEntity === null) {
293+
return;
294+
}
295+
296+
// Assert custom values are applied
297+
assert.addressEquals(
298+
Address.fromBytes(priceRequestEntity.currency),
299+
Address.fromString(Constants.currency_2),
300+
"Currency should match"
301+
);
302+
303+
assert.bigIntEquals(
304+
priceRequestEntity.bond!,
305+
BigInt.fromI32(Constants.customBond_2),
306+
"Custom bond should be applied to RequestPrice"
307+
);
308+
309+
assert.bigIntEquals(
310+
priceRequestEntity.customLiveness!,
311+
BigInt.fromI32(Constants.customLiveness),
312+
"Custom liveness should be applied to RequestPrice"
313+
);
314+
315+
log.info("Created OptimisticPriceRequest entity: {}", [priceRequestEntity.id]);
316+
log.info("Custom Liveness: {}", [priceRequestEntity.customLiveness!.toString()]);
317+
log.info("State: {}", [priceRequestEntity.state!]);
318+
log.info("Custom Bond: {}", [priceRequestEntity.bond!.toString()]);
319+
log.info("Custom Bond Currency: {}", [priceRequestEntity.currency!.toHexString()]);
320+
});
215321
});

packages/managed-oracle-v2/tests/managed-oracle-v2/utils.ts

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { createMockedFunction, newMockEvent } from "matchstick-as";
22
import { ethereum, BigInt, Address, Bytes } from "@graphprotocol/graph-ts";
3-
import { CustomBondSet, CustomLivenessSet, RequestPrice } from "../../generated/ManagedOracleV2/ManagedOracleV2";
3+
import {
4+
CustomBondSet,
5+
CustomLivenessSet,
6+
ProposePrice,
7+
RequestPrice,
8+
} from "../../generated/ManagedOracleV2/ManagedOracleV2";
49

510
export const contractAddress = Address.fromString("0x89205A3A3b2A69De6Dbf7f01ED13B2108B2c43e7"); // Default test contract address
611

@@ -122,6 +127,59 @@ export function createRequestPriceEvent(
122127
return requestPriceEvent;
123128
}
124129

130+
export function createProposePriceEvent(
131+
requester: string, // Address,
132+
proposer: string, // Address,
133+
identifier: string, // Bytes,
134+
timestamp: i32, // BigInt,
135+
ancillaryData: string, // Bytes,
136+
proposedPrice: i32, // BigInt,
137+
expirationTimestamp: i32, // BigInt,
138+
currency: string // Address
139+
): ProposePrice {
140+
let proposePriceEvent = changetype<ProposePrice>(newMockEvent());
141+
proposePriceEvent.address = contractAddress;
142+
proposePriceEvent.parameters = new Array();
143+
144+
// requester
145+
proposePriceEvent.parameters.push(
146+
new ethereum.EventParam("requester", ethereum.Value.fromAddress(Address.fromString(requester)))
147+
);
148+
// proposer
149+
proposePriceEvent.parameters.push(
150+
new ethereum.EventParam("proposer", ethereum.Value.fromAddress(Address.fromString(proposer)))
151+
);
152+
// identifier
153+
proposePriceEvent.parameters.push(
154+
new ethereum.EventParam("identifier", ethereum.Value.fromBytes(Bytes.fromHexString(identifier)))
155+
);
156+
// timestamp
157+
proposePriceEvent.parameters.push(
158+
new ethereum.EventParam("timestamp", ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(timestamp)))
159+
);
160+
// ancillaryData
161+
proposePriceEvent.parameters.push(
162+
new ethereum.EventParam("ancillaryData", ethereum.Value.fromBytes(Bytes.fromHexString(ancillaryData)))
163+
);
164+
// proposedPrice
165+
proposePriceEvent.parameters.push(
166+
new ethereum.EventParam("proposedPrice", ethereum.Value.fromSignedBigInt(BigInt.fromI32(proposedPrice)))
167+
);
168+
// expirationTimestamp
169+
proposePriceEvent.parameters.push(
170+
new ethereum.EventParam(
171+
"expirationTimestamp",
172+
ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(expirationTimestamp))
173+
)
174+
);
175+
// currency
176+
proposePriceEvent.parameters.push(
177+
new ethereum.EventParam("currency", ethereum.Value.fromAddress(Address.fromString(currency)))
178+
);
179+
180+
return proposePriceEvent;
181+
}
182+
125183
// https://github.com/UMAprotocol/protocol/blob/99b96247d27ec8a5ea9dbf3eef1dcd71beb0dc41/packages/core/contracts/optimistic-oracle-v2/interfaces/OptimisticOracleV2Interface.sol#L51
126184
export namespace State {
127185
export const Invalid = 0; // Never requested

0 commit comments

Comments
 (0)