-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apply vote amount cap to votes (#259)
* apply vote amount cap to votes * refactor: move voteAmountCap definition to general chain configuration --------- Co-authored-by: Massimiliano Mirra <[email protected]>
- Loading branch information
1 parent
721da24
commit 2aa2534
Showing
10 changed files
with
284 additions
and
15 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,55 @@ | ||
import { Chain } from "../config.js"; | ||
import type { Vote } from "../indexer/types.js"; | ||
|
||
enum ChainId { | ||
Fantom = 250, | ||
} | ||
|
||
type TokenAddress = Lowercase<`0x${string}`>; | ||
|
||
type TokensSettings = { | ||
[chainId in ChainId]: { | ||
[tokenAddress: TokenAddress]: { | ||
voteAmountCap: bigint | undefined; | ||
}; | ||
}; | ||
}; | ||
|
||
export const FANTOM_GCV: TokenAddress = | ||
"0x83791638da5eb2faa432aff1c65fba47c5d29510"; | ||
|
||
// For now this mapping contains one single token. | ||
// We can continue adding tokens here, but in the future it will | ||
// be better to save the voteAmountCap in the roundMetadata and having | ||
// this fields editable in Grants Stack. | ||
export const tokensSettings: TokensSettings = { | ||
250: { | ||
[FANTOM_GCV]: { | ||
voteAmountCap: BigInt(10e18), | ||
}, | ||
}, | ||
}; | ||
|
||
export function applyVoteCap(chain: Chain, vote: Vote): Vote { | ||
const tokenConfig = chain.tokens.find( | ||
(t) => t.address.toLowerCase() === vote.token.toLowerCase() | ||
); | ||
|
||
if (tokenConfig === undefined) { | ||
throw new Error(`Unknown token: ${vote.token}`); | ||
} | ||
|
||
const { voteAmountCap } = tokenConfig; | ||
if (voteAmountCap === undefined) { | ||
return vote; | ||
} else { | ||
// amount : amountRoundToken = voteAmountCap : newAmountRoundToken | ||
const newAmountRoundToken = | ||
(BigInt(vote.amountRoundToken) * voteAmountCap) / BigInt(vote.amount); | ||
|
||
return { | ||
...vote, | ||
amountRoundToken: newAmountRoundToken.toString(), | ||
}; | ||
} | ||
} |
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
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
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.