-
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
Changes from 11 commits
a3b71fa
36fecc6
f1e2161
a66e8f7
a27e880
ba820f7
49b6a56
f117ab6
1737185
724a9d6
3bbc92f
c789021
f2be773
9708d53
5360984
91b6357
0b981a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,9 +85,9 @@ export default class CeloProvider extends JsonRpcProvider { | |
"%response" | ||
); | ||
} | ||
|
||
async getFeeData(feeCurrency?: string): Promise<FeeData> { | ||
if (!feeCurrency) { | ||
// for eip1559 and cip66 transactions are denominated in CELO, cip64 fees must be looked up in the fee token | ||
async getFeeData(feeCurrency?: string, denominateInCelo?: boolean): Promise<FeeData> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What purpose does this new param serve? When would denominate be true but fee currency would be truthy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because with this new transaction type feeCurrency exists but intead of maxFeePerGas and maxPriorityFeePerGas needing be looked up in that in the price for that token they are instead priced in CELO. |
||
if (!feeCurrency || denominateInCelo) { | ||
return super.getFeeData(); | ||
} | ||
// On Celo, `eth_gasPrice` returns the base fee for the given currency multiplied 2 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
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}: {wallet: CeloWallet}): Promise<[bigint, bigint]> { | ||
aaronmgdr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const registry = new Contract(CELO_REGISTRY_ADDRESS, MINIMAL_REGISTRY_ABI , wallet) | ||
aaronmgdr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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] | ||
} |
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