-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-contract-sync.js
More file actions
executable file
Β·239 lines (209 loc) Β· 6.93 KB
/
Copy pathfix-contract-sync.js
File metadata and controls
executable file
Β·239 lines (209 loc) Β· 6.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env node
const { createPublicClient, createWalletClient, http, privateKeyToAccount } = require('viem');
// Somnia network configuration
const chain = {
id: 50312,
name: 'Somnia',
nativeCurrency: {
decimals: 18,
name: 'ETH',
symbol: 'ETH',
},
rpcUrls: {
default: {
http: ['https://dream-rpc.somnia.network/']
}
}
};
const ODDYSSEY_ADDRESS = '0x70D7D101641c72b8254Ab45Ff2a5CED9b0ad0E75';
// Get private key from environment or prompt
const PRIVATE_KEY = process.env.PRIVATE_KEY || process.env.BOT_PRIVATE_KEY;
if (!PRIVATE_KEY) {
console.error('β Private key not found. Set PRIVATE_KEY or BOT_PRIVATE_KEY environment variable.');
process.exit(1);
}
const account = privateKeyToAccount(PRIVATE_KEY);
const publicClient = createPublicClient({
chain,
transport: http('https://dream-rpc.somnia.network/')
});
const walletClient = createWalletClient({
account,
chain,
transport: http('https://dream-rpc.somnia.network/')
});
// Sample matches for testing
const sampleMatches = [
{
id: 1n,
startTime: BigInt(Math.floor(Date.now() / 1000) + 3600), // 1 hour from now
oddsHome: 2000n, // 2.0 odds
oddsDraw: 3500n, // 3.5 odds
oddsAway: 4000n, // 4.0 odds
oddsOver: 1800n, // 1.8 odds
oddsUnder: 2200n, // 2.2 odds
result: {
moneyline: 0, // NotSet
overUnder: 0 // NotSet
}
},
{
id: 2n,
startTime: BigInt(Math.floor(Date.now() / 1000) + 3600),
oddsHome: 1500n,
oddsDraw: 4000n,
oddsAway: 6000n,
oddsOver: 1900n,
oddsUnder: 2100n,
result: {
moneyline: 0,
overUnder: 0
}
},
{
id: 3n,
startTime: BigInt(Math.floor(Date.now() / 1000) + 3600),
oddsHome: 3000n,
oddsDraw: 3200n,
oddsAway: 2500n,
oddsOver: 2000n,
oddsUnder: 1900n,
result: {
moneyline: 0,
overUnder: 0
}
}
];
// Pad to 10 matches
while (sampleMatches.length < 10) {
const baseMatch = sampleMatches[sampleMatches.length % 3];
sampleMatches.push({
...baseMatch,
id: BigInt(sampleMatches.length + 1)
});
}
// Basic ABI for startDailyCycle
const ODDYSSEY_ABI = [
{
"inputs": [
{
"components": [
{"internalType": "uint256", "name": "id", "type": "uint256"},
{"internalType": "uint256", "name": "startTime", "type": "uint256"},
{"internalType": "uint256", "name": "oddsHome", "type": "uint256"},
{"internalType": "uint256", "name": "oddsDraw", "type": "uint256"},
{"internalType": "uint256", "name": "oddsAway", "type": "uint256"},
{"internalType": "uint256", "name": "oddsOver", "type": "uint256"},
{"internalType": "uint256", "name": "oddsUnder", "type": "uint256"},
{
"components": [
{"internalType": "uint8", "name": "moneyline", "type": "uint8"},
{"internalType": "uint8", "name": "overUnder", "type": "uint8"}
],
"internalType": "struct IOddyssey.Result",
"name": "result",
"type": "tuple"
}
],
"internalType": "struct IOddyssey.Match[10]",
"name": "_matches",
"type": "tuple[10]"
}
],
"name": "startDailyCycle",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
];
async function fixContractSync() {
try {
console.log('π Fixing Oddyssey Contract Synchronization...');
console.log('π Contract Address:', ODDYSSEY_ADDRESS);
console.log('π€ Account:', account.address);
console.log('=' .repeat(80));
// Check current state
console.log('\n1οΈβ£ Checking current contract state...');
const currentCycle = await publicClient.readContract({
address: ODDYSSEY_ADDRESS,
abi: [{
"inputs": [],
"name": "getCurrentCycle",
"outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
"stateMutability": "view",
"type": "function"
}],
functionName: 'getCurrentCycle'
});
console.log(' Current contract cycle:', currentCycle.toString());
if (currentCycle > 0n) {
console.log('β
Contract already has cycles. Sync may not be needed.');
return;
}
// Check balance
const balance = await publicClient.getBalance({ address: account.address });
console.log(' Account balance:', (Number(balance) / 1e18).toFixed(4), 'ETH');
if (balance === 0n) {
console.error('β Account has no balance for gas fees');
return;
}
// Estimate gas for startDailyCycle
console.log('\n2οΈβ£ Preparing to start daily cycle...');
console.log(' Sample matches prepared:', sampleMatches.length);
try {
const gasEstimate = await publicClient.estimateContractGas({
account,
address: ODDYSSEY_ADDRESS,
abi: ODDYSSEY_ABI,
functionName: 'startDailyCycle',
args: [sampleMatches]
});
console.log(' Estimated gas:', gasEstimate.toString());
// Execute the transaction
console.log('\n3οΈβ£ Executing startDailyCycle...');
const hash = await walletClient.writeContract({
address: ODDYSSEY_ADDRESS,
abi: ODDYSSEY_ABI,
functionName: 'startDailyCycle',
args: [sampleMatches],
gas: gasEstimate * 120n / 100n // Add 20% buffer
});
console.log('π Transaction sent:', hash);
console.log('β³ Waiting for confirmation...');
const receipt = await publicClient.waitForTransactionReceipt({ hash });
console.log('β
Transaction confirmed in block:', receipt.blockNumber);
// Verify the cycle was created
console.log('\n4οΈβ£ Verifying cycle creation...');
const newCycle = await publicClient.readContract({
address: ODDYSSEY_ADDRESS,
abi: [{
"inputs": [],
"name": "getCurrentCycle",
"outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
"stateMutability": "view",
"type": "function"
}],
functionName: 'getCurrentCycle'
});
console.log(' New contract cycle:', newCycle.toString());
if (newCycle > 0n) {
console.log('π SUCCESS! Contract is now synchronized with cycle', newCycle.toString());
} else {
console.log('β οΈ Contract cycle still 0. Check if transaction reverted.');
}
} catch (gasError) {
console.error('β Gas estimation failed:', gasError.message);
if (gasError.message.includes('execution reverted')) {
console.log('\nπ Transaction would revert. Possible reasons:');
console.log(' - Not authorized to call startDailyCycle');
console.log(' - Contract conditions not met');
console.log(' - Invalid match data format');
console.log(' - Contract paused or has other restrictions');
}
}
} catch (error) {
console.error('π₯ Error fixing contract sync:', error);
}
}
// Run the fix
fixContractSync().catch(console.error);