-
Notifications
You must be signed in to change notification settings - Fork 213
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
feat(target_chains/fuel): update fuel toolchains to the latest version #1911
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
} | ||
} | ||
|
||
let gi = GovernanceInstruction::parse_governance_instruction(vm.payload); | ||
// Log so that the GovernanceInstruction struct will show up in the ABI and can be used in the tests | ||
log(gi); | ||
#[storage(read, write)] | ||
fn execute_governance_instruction(encoded_vm: Bytes) { | ||
let vm = verify_governance_vm(encoded_vm); | ||
// Log so that the WormholeVM struct will show up in the ABI and can be used in the tests | ||
log(vm); | ||
|
||
require( | ||
gi.target_chain_id == chain_id() || gi.target_chain_id == 0, | ||
PythError::InvalidGovernanceTarget, | ||
); | ||
let gi = GovernanceInstruction::parse_governance_instruction(vm.payload); | ||
// Log so that the GovernanceInstruction struct will show up in the ABI and can be used in the tests | ||
log(gi); | ||
|
||
match gi.action { | ||
GovernanceAction::UpgradeContract => { | ||
require(gi.target_chain_id != 0, PythError::InvalidGovernanceTarget); | ||
// TODO: implement upgrade_upgradeable_contract(uc) when Fuel releases the upgrade standard library; | ||
log("Upgrade functionality not implemented"); | ||
revert(0u64); | ||
}, | ||
GovernanceAction::AuthorizeGovernanceDataSourceTransfer => { | ||
let agdst = GovernanceInstruction::parse_authorize_governance_data_source_transfer_payload(gi.payload); | ||
log(agdst); | ||
authorize_governance_data_source_transfer(agdst); | ||
}, | ||
GovernanceAction::SetDataSources => { | ||
let sdsp = GovernanceInstruction::parse_set_data_sources_payload(gi.payload); | ||
log(sdsp); | ||
set_data_sources(sdsp); | ||
}, | ||
GovernanceAction::SetFee => { | ||
let sf = GovernanceInstruction::parse_set_fee_payload(gi.payload); | ||
log(sf); | ||
set_fee(sf); | ||
}, | ||
GovernanceAction::SetValidPeriod => { | ||
let svp = GovernanceInstruction::parse_set_valid_period_payload(gi.payload); | ||
log(svp); | ||
set_valid_period(svp); | ||
}, | ||
GovernanceAction::RequestGovernanceDataSourceTransfer => { | ||
// RequestGovernanceDataSourceTransfer can be only part of AuthorizeGovernanceDataSourceTransfer message | ||
// The `revert` function only accepts u64, so as | ||
// a workaround we use require. | ||
require(false, PythError::InvalidGovernanceMessage); | ||
}, | ||
_ => { | ||
// The `revert` function only accepts u64, so as | ||
// a workaround we use require. | ||
require(false, PythError::InvalidGovernanceMessage); | ||
} | ||
require( | ||
gi.target_chain_id == chain_id() || gi.target_chain_id == 0, | ||
PythError::InvalidGovernanceTarget, | ||
); | ||
|
||
match gi.action { | ||
GovernanceAction::UpgradeContract => { | ||
require(gi.target_chain_id != 0, PythError::InvalidGovernanceTarget); | ||
// TODO: implement upgrade_upgradeable_contract(uc) when Fuel releases the upgrade standard library; | ||
log("Upgrade functionality not implemented"); | ||
revert(0u64); | ||
}, | ||
GovernanceAction::AuthorizeGovernanceDataSourceTransfer => { | ||
let agdst = GovernanceInstruction::parse_authorize_governance_data_source_transfer_payload(gi.payload); | ||
log(agdst); | ||
authorize_governance_data_source_transfer(agdst); | ||
}, | ||
GovernanceAction::SetDataSources => { | ||
let sdsp = GovernanceInstruction::parse_set_data_sources_payload(gi.payload); | ||
log(sdsp); | ||
set_data_sources(sdsp); | ||
}, | ||
GovernanceAction::SetFee => { | ||
let sf = GovernanceInstruction::parse_set_fee_payload(gi.payload); | ||
log(sf); | ||
set_fee(sf); | ||
}, | ||
GovernanceAction::SetValidPeriod => { | ||
let svp = GovernanceInstruction::parse_set_valid_period_payload(gi.payload); | ||
log(svp); | ||
set_valid_period(svp); | ||
}, | ||
GovernanceAction::RequestGovernanceDataSourceTransfer => { | ||
// RequestGovernanceDataSourceTransfer can be only part of AuthorizeGovernanceDataSourceTransfer message | ||
// The `revert` function only accepts u64, so as | ||
// a workaround we use require. | ||
require(false, PythError::InvalidGovernanceMessage); | ||
}, | ||
_ => { | ||
// The `revert` function only accepts u64, so as | ||
// a workaround we use require. | ||
require(false, PythError::InvalidGovernanceMessage); |
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.
there is a compiler issue with fuel where it fails to compile with Too many arguments, cannot handle.: Immediate12TooLarge
error and the solution was to make the contract functions call internal functions, more context here: FuelLabs/sway#6542
```typescript | ||
import { HermesClient, PriceUpdate } from "@pythnetwork/hermes-client"; | ||
import { | ||
PYTH_CONTRACT_ADDRESS_SEPOLIA, | ||
PYTH_CONTRACT_ABI, | ||
FUEL_ETH_ASSET_ID, | ||
} from "../index"; | ||
import { Provider, Wallet, Contract, hexlify, arrayify } from "fuels"; | ||
|
||
async function main() { | ||
// Create a provider for interacting with Fuel RPC | ||
const provider = await Provider.create( | ||
"https://testnet.fuel.network/v1/graphql" | ||
); | ||
const privateKey = process.env.ACCOUNT_PRIVATE_KEY; | ||
if (privateKey === undefined) { | ||
throw new Error("Missing ACCOUNT_PRIVATE_KEY env var"); | ||
} | ||
const wallet = Wallet.fromPrivateKey(privateKey, provider); | ||
|
||
// Create a `Contract` instance to interact with the Pyth contract on Fuel | ||
const contract = new Contract( | ||
PYTH_CONTRACT_ADDRESS_SEPOLIA, | ||
PYTH_CONTRACT_ABI, | ||
wallet | ||
); | ||
|
||
const priceFeedSymbol = "Crypto.ETH/USD"; | ||
const priceFeedId = | ||
"0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace"; // Pyth ETH/USD price feed id | ||
const previousPrice = ( | ||
await contract.functions.price_unsafe(priceFeedId).get() | ||
).value; | ||
console.log( | ||
`Previous price: ${ | ||
previousPrice.price.toNumber() * 10 ** -previousPrice.exponent | ||
}` | ||
); | ||
|
||
// Create a client for pulling price updates from Hermes. | ||
const hermesClient = new HermesClient("https://hermes.pyth.network"); | ||
|
||
console.log(`Querying latest Pyth price update for ${priceFeedSymbol}`); | ||
// Get the latest values of the price feeds as json objects. | ||
const priceUpdates: PriceUpdate = await hermesClient.getLatestPriceUpdates([ | ||
priceFeedId, | ||
]); | ||
console.log( | ||
`Current price from Hermes: ${ | ||
Number(priceUpdates.parsed?.[0].price.price) * | ||
10 ** Number(priceUpdates.parsed?.[0].price.expo) | ||
}` | ||
); | ||
|
||
const priceFeedUpdateData = arrayify( | ||
Buffer.from(priceUpdates.binary.data[0], "hex") | ||
); | ||
|
||
// Query the amount of update fee required | ||
console.log(`Querying update fee...`); | ||
const updateFee: number = ( | ||
await contract.functions.update_fee([priceFeedUpdateData]).get() | ||
).value; | ||
console.log(`Update fee: ${updateFee}`); | ||
|
||
const tx = await contract.functions | ||
.update_price_feeds([priceFeedUpdateData]) | ||
.callParams({ | ||
forward: [updateFee, hexlify(FUEL_ETH_ASSET_ID)], | ||
}) | ||
.call(); | ||
console.log(`Transaction confirmed: ${tx.transactionId}`); | ||
|
||
const newPrice = ( | ||
await contract.functions.price_no_older_than(60, priceFeedId).get() | ||
).value; | ||
console.log( | ||
`New price: ${newPrice.price.toNumber() * 10 ** -newPrice.exponent}` | ||
); | ||
} | ||
|
||
main(); | ||
``` |
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.
refactored this into src/examples/usage.ts
because i saw that in package.lock
there is "usage-example": "ts-node src/examples/usage.ts"
but the file doesn't exists
No description provided.