1
1
// This script is used to help test OO interfaces on testnets by producing a set of OO requests.
2
2
3
+ import { ERC20 } from "@uma/contracts-node/typechain/core/ethers" ;
3
4
import { getContractInstance } from "../utils/contracts" ;
4
5
5
6
import {
@@ -8,12 +9,13 @@ import {
8
9
SkinnyOptimisticOracleEthers ,
9
10
OptimisticOracleV3Ethers ,
10
11
} from "@uma/contracts-node" ;
12
+ import { BigNumber } from "ethers" ;
13
+ import { toUtf8Bytes } from "ethers/lib/utils" ;
11
14
12
15
const hre = require ( "hardhat" ) ;
13
16
const { ethers } = hre ;
14
17
15
- const ancillaryData =
16
- "0x713a207469746c653a2057696c6c20446f6e616c64204a2e205472756d7020626520696e64696374656420627920417072696c2031343f2c206465736372697074696f6e3a2054686973206d61726b65742077696c6c207265736f6c766520746f20e2809c596573e2809d20696620616e79204665646572616c206f72205374617465206a7572697364696374696f6e206f662074686520556e697465642053746174657320756e7365616c73206f72206f7468657277697365206f6666696369616c6c7920616e6e6f756e6365732061206372696d696e616c20696e646963746d656e74206f6620666f726d657220507265736964656e7420446f6e616c64205472756d70206265666f726520746865207265736f6c7574696f6e2074696d6520417072696c2031342c20323032332c2031313a35393a353920504d2045542e204f74686572776973652c2074686973206d61726b65742077696c6c207265736f6c766520746f20e2809c4e6fe2809d2e0a0a506c65617365206e6f74652c20666f7220707572706f736573206f662074686973206d61726b65742c20746865204469737472696374206f6620436f6c756d62696120616e6420616e7920636f756e74792c206d756e69636970616c6974792c206f72206f74686572207375626469766973696f6e206f662061205374617465207368616c6c20626520696e636c756465642077697468696e2074686520646566696e6974696f6e206f6620612053746174652e0a4e6f746520616c736f2c207468617420616e20696e646963746d656e74207468617420686173206265656e20697373756564206265666f726520746865207265736f6c7574696f6e2074696d65206275742072656d61696e73207365616c6564206f72206f74686572776973652073656372657420617420746865207265736f6c7574696f6e2074696d652077696c6c206e6f7420626520636f6e7369646572656420696e2074686973206d61726b65742e207265735f646174613a2070313a20302c2070323a20312c2070333a20302e352e20576865726520703120636f72726573706f6e647320746f204e6f2c20703220746f205965732c20703320746f20756e6b6e6f776e2f35302d35302c696e697469616c697a65723a393134333063616432643339373537363634393937313766613064363661373864383134653563352c6f6f5265717565737465723a366139643232323631366339306663613537353463643133333363666439623766623661346637342c6368696c645265717565737465723a656533616665333437643563373433313730343165323631386334393533346461663838376332342c6368696c64436861696e49643a313337" ;
18
+ const ancillaryData = toUtf8Bytes ( `q:"Really hard question, maybe 100, maybe 90?"` ) ;
17
19
18
20
const yesNoIdentifier = "0x5945535f4f525f4e4f5f51554552590000000000000000000000000000000000" ;
19
21
@@ -23,38 +25,55 @@ const defaultBondOrReward = "10000";
23
25
24
26
const defaultLiveness = "7200" ;
25
27
26
- const goerliUsdc = "0x07865c6E87B9F70255377e024ace6630C1Eaa37F " ;
28
+ const sepoliaUsdc = "0x20205D46ae5299d8E99B98042ebb4B2999169d3A " ;
27
29
28
30
const requestTime = Math . floor ( new Date ( ) . valueOf ( ) / 1000 ) - 1000 ;
29
31
32
+ const approveIfNecessary = async ( token : ERC20 , spender : string , amount : BigNumber ) => {
33
+ const wallet = ( await ethers . provider . listAccounts ( ) ) [ 0 ] ;
34
+ const allowance = await token . allowance ( wallet , spender ) ;
35
+ if ( allowance . lt ( amount ) ) {
36
+ const approveTx = await token . approve ( spender , ethers . constants . MaxUint256 ) ;
37
+ await approveTx . wait ( ) ;
38
+ }
39
+ } ;
40
+
30
41
async function main ( ) {
31
42
console . log ( "Running OptimisticOracleRequestSender script 🚀" ) ;
32
43
33
44
const chainId = ( await ethers . provider . getNetwork ( ) ) . chainId ;
34
45
35
- if ( ! chainId || chainId != 5 ) throw new Error ( "This script should be run on goerli" ) ;
46
+ const collateralToken = await getContractInstance < ERC20 > ( "ERC20" , sepoliaUsdc , chainId ) ;
36
47
37
- // OO v1.
38
- const optimisticOracle = await getContractInstance < OptimisticOracleEthers > ( "OptimisticOracle" , undefined , 5 ) ;
48
+ if ( ! chainId || chainId != 11155111 ) throw new Error ( "This script should be run on sepolia" ) ;
49
+
50
+ // OO v1.
51
+ const optimisticOracle = await getContractInstance < OptimisticOracleEthers > ( "OptimisticOracle" , undefined , chainId ) ;
52
+ await approveIfNecessary ( collateralToken , optimisticOracle . address , BigNumber . from ( defaultBondOrReward ) ) ;
39
53
console . log ( "Sending requests to OptimisticOracle" , optimisticOracle . address ) ;
40
54
const ooTx = await optimisticOracle . requestPrice (
41
55
yesNoIdentifier ,
42
56
requestTime ,
43
57
ancillaryData ,
44
- goerliUsdc ,
58
+ sepoliaUsdc ,
45
59
defaultBondOrReward
46
60
) ;
47
61
ooTx . wait ( ) ;
48
62
console . log ( "Sent request to OptimisticOracle" , ooTx . hash ) ;
49
63
50
64
// OO v2.
51
- const optimisticOracleV2 = await getContractInstance < OptimisticOracleV2Ethers > ( "OptimisticOracleV2" , undefined , 5 ) ;
65
+ const optimisticOracleV2 = await getContractInstance < OptimisticOracleV2Ethers > (
66
+ "OptimisticOracleV2" ,
67
+ undefined ,
68
+ chainId
69
+ ) ;
70
+ await approveIfNecessary ( collateralToken , optimisticOracleV2 . address , BigNumber . from ( defaultBondOrReward ) ) ;
52
71
console . log ( "Sending requests to OptimisticOracleV2" , optimisticOracleV2 . address ) ;
53
72
const ooV2Tx = await optimisticOracleV2 . requestPrice (
54
73
yesNoIdentifier ,
55
74
requestTime ,
56
75
ancillaryData ,
57
- goerliUsdc ,
76
+ sepoliaUsdc ,
58
77
defaultBondOrReward
59
78
) ;
60
79
ooV2Tx . wait ( ) ;
@@ -64,14 +83,15 @@ async function main() {
64
83
const skinnyOptimisticOracle = await getContractInstance < SkinnyOptimisticOracleEthers > (
65
84
"SkinnyOptimisticOracle" ,
66
85
undefined ,
67
- 5
86
+ chainId
68
87
) ;
88
+ await approveIfNecessary ( collateralToken , skinnyOptimisticOracle . address , BigNumber . from ( defaultBondOrReward ) ) ;
69
89
console . log ( "Sending requests to SkinnyOptimisticOracle" , skinnyOptimisticOracle . address ) ;
70
90
const ooSkinnyTx = await skinnyOptimisticOracle . requestPrice (
71
91
yesNoIdentifier ,
72
92
requestTime ,
73
93
ancillaryData ,
74
- goerliUsdc ,
94
+ sepoliaUsdc ,
75
95
defaultBondOrReward ,
76
96
defaultBondOrReward ,
77
97
defaultLiveness
@@ -80,7 +100,12 @@ async function main() {
80
100
console . log ( "Sent request to SkinnyOptimisticOracle" , ooSkinnyTx . hash ) ;
81
101
82
102
// OO v3.
83
- const optimisticOracleV3 = await getContractInstance < OptimisticOracleV3Ethers > ( "OptimisticOracleV3" , undefined , 5 ) ;
103
+ const optimisticOracleV3 = await getContractInstance < OptimisticOracleV3Ethers > (
104
+ "OptimisticOracleV3" ,
105
+ undefined ,
106
+ chainId
107
+ ) ;
108
+ await approveIfNecessary ( collateralToken , optimisticOracleV3 . address , BigNumber . from ( defaultBondOrReward ) ) ;
84
109
console . log ( "Sending requests to OptimisticOracleV3" , optimisticOracleV3 . address ) ;
85
110
const claim = ethers . utils . formatBytes32String ( "The sky is blue" ) ;
86
111
const ooV3Tx = await optimisticOracleV3 . assertTruth (
@@ -89,7 +114,7 @@ async function main() {
89
114
"0x0000000000000000000000000000000000000000" ,
90
115
"0x0000000000000000000000000000000000000000" ,
91
116
defaultLiveness ,
92
- goerliUsdc ,
117
+ sepoliaUsdc ,
93
118
defaultBondOrReward ,
94
119
asserterIdentifier ,
95
120
"0x0000000000000000000000000000000000000000000000000000000000000000"
0 commit comments