-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for cip 66 transactions #23
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a3b71fa
CIP-66 support
shazarre 36fecc6
move tests that dont use network / unit tests to own file
aaronmgdr f1e2161
make functions type guard
aaronmgdr a66e8f7
Numeric type allows number which will lead to issues. just do bigint
aaronmgdr a27e880
conditionally fill the transaction for cip66 if on cel2.
aaronmgdr ba820f7
fetches exchange rate from the SortedOracles Contract
aaronmgdr 49b6a56
clean up notes
aaronmgdr f117ab6
more notes
aaronmgdr 1737185
real world sanity check for max Fees in Celo 110000000000000000000n …
aaronmgdr 724a9d6
spelling
aaronmgdr 3bbc92f
improve param names
aaronmgdr c789021
extra line
aaronmgdr f2be773
formatting
aaronmgdr 9708d53
allow access list to be used
aaronmgdr 5360984
get types correct.
aaronmgdr 91b6357
allow access list to be used
aaronmgdr 0b981a3
run npx prettier -w --no-config . but only keep formatting for chan…
aaronmgdr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Contract } from "ethers"; | ||
import CeloWallet from "./CeloWallet"; | ||
import { CELO_REGISTRY_ADDRESS } from "../consts"; | ||
|
||
const MINIMAL_ORACLE_INTERFACE = [ | ||
{ | ||
constant: true, | ||
inputs: [ | ||
{ | ||
internalType: "address", | ||
name: "token", | ||
type: "address", | ||
}, | ||
], | ||
name: "medianRate", | ||
outputs: [ | ||
{ | ||
internalType: "uint256", | ||
name: "", | ||
type: "uint256", | ||
}, | ||
{ | ||
internalType: "uint256", | ||
name: "", | ||
type: "uint256", | ||
}, | ||
], | ||
payable: false, | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
]; | ||
|
||
const MINIMAL_REGISTRY_ABI = [ | ||
{ | ||
constant: true, | ||
inputs: [ | ||
{ | ||
internalType: "string", | ||
name: "identifier", | ||
type: "string", | ||
}, | ||
], | ||
name: "getAddressForString", | ||
outputs: [ | ||
{ | ||
internalType: "address", | ||
name: "", | ||
type: "address", | ||
}, | ||
], | ||
payable: false, | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
]; | ||
|
||
export async function getConversionRateFromCeloToToken( | ||
tokenAddress: string, | ||
wallet: CeloWallet, | ||
): Promise<[bigint, bigint]> { | ||
const registry = new Contract( | ||
CELO_REGISTRY_ADDRESS, | ||
MINIMAL_REGISTRY_ABI, | ||
wallet, | ||
); | ||
|
||
const oracleAddress = await registry.getAddressForString("SortedOracles"); | ||
|
||
const oracle = new Contract(oracleAddress, MINIMAL_ORACLE_INTERFACE, wallet); | ||
|
||
const [numerator, denominator]: bigint[] = | ||
await oracle.medianRate(tokenAddress); | ||
// The function docs for the Contract are confusing but in ContractKit the Sorted orcles wrapper | ||
// defines numerator as the amount of the token and denominiator as equvalent value in CELO | ||
// https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/SortedOracles.ts#L80 | ||
// https://github.com/celo-org/celo-monorepo/blob/master/packages/protocol/contracts/stability/SortedOracles.sol | ||
return [numerator, denominator]; | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed and means that calling yarn test does not work