-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9550 from hicommonwealth/9449-updating-prize-amou…
…nts-on-contests-faster Client side prize amounts on contests
- Loading branch information
Showing
15 changed files
with
317 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { ZERO_ADDRESS } from '@hicommonwealth/shared'; | ||
|
||
export const getTotalContestBalance = async ( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
contestContract: any, | ||
contestAddress: string, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
web3: any, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
feeManagerAbi: any[], | ||
oneOff?: boolean, | ||
): Promise<number> => { | ||
const promises = [contestContract.methods.contestToken().call()]; | ||
|
||
if (!oneOff) { | ||
promises.push(contestContract.methods.FeeMangerAddress().call()); | ||
} | ||
|
||
const results = await Promise.all(promises); | ||
|
||
const balancePromises: Promise<number>[] = []; | ||
|
||
if (!oneOff) { | ||
const feeManager = new web3.eth.Contract(feeManagerAbi, String(results[1])); | ||
balancePromises.push( | ||
feeManager.methods | ||
.getBeneficiaryBalance(contestAddress, results[0]) | ||
.call(), | ||
); | ||
} | ||
if (String(results[0]) === ZERO_ADDRESS) { | ||
balancePromises.push( | ||
web3.eth.getBalance(contestAddress).then((v: bigint) => { | ||
return Number(v); | ||
}), | ||
); | ||
} else { | ||
const calldata = | ||
'0x70a08231' + | ||
web3.eth.abi.encodeParameters(['address'], [contestAddress]).substring(2); | ||
balancePromises.push( | ||
web3.eth | ||
.call({ | ||
to: String(results[0]), | ||
data: calldata, | ||
}) | ||
.then((v: string) => { | ||
return Number(web3.eth.abi.decodeParameter('uint256', v)); | ||
}), | ||
); | ||
} | ||
|
||
const balanceResults = await Promise.all(balancePromises); | ||
|
||
return Number( | ||
balanceResults.length === 2 | ||
? BigInt(balanceResults[0]) + BigInt(balanceResults[1]) | ||
: BigInt(balanceResults[0]), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './chainConfig'; | ||
export * from './contractHelpers/Contest'; | ||
export * from './contractHelpers/Launchpad'; | ||
export * from './utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/commonwealth/client/scripts/helpers/ContractHelpers/Abi/feeManagerAbi.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const feeManagerABI = [ | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: 'address', | ||
name: 'beneficiary', | ||
type: 'address', | ||
}, | ||
{ | ||
internalType: 'address', | ||
name: 'token', | ||
type: 'address', | ||
}, | ||
], | ||
name: 'getBeneficiaryBalance', | ||
outputs: [ | ||
{ | ||
internalType: 'uint256', | ||
name: '', | ||
type: 'uint256', | ||
}, | ||
], | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.