Last active
September 9, 2023 09:25
-
-
Save dmshvetsov/5d15d947e3f7c90bd19acce18ae45b22 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module 0xA::pyth_oracle_n_coin_transfer_a { | |
struct State { | |
// a place where depositor, asset and amount is stored | |
} | |
public entry fun colatarize_asset<Asset>(depositor: &signer, amount: u64) { | |
let resource_account = get_resource_account(); | |
coint::transfe<Asset>( | |
depositor, | |
resource_account, | |
amount | |
); | |
let at_price = get_asset_price_with_pyth<Asset>(); | |
let depositor_address = signer::address_of(depositor): | |
add_colateral_record_to_state<Asset>(depositor_address, amount, at_price); | |
} | |
fun get_asset_price_with_pyth<Asset>(): Price { | |
pyth::get_price( | |
// TODO: how to get price knowing generic Asset | |
price_identifier::from_byte_vec(asset_id) | |
) | |
}; | |
fun add_colateral_record_to_state<Asset>() acquires State; | |
fun get_resource_account(): address; | |
} | |
module 0xA::pyth_oracle_n_coin_transfer_b { | |
struct State { | |
// a place where depositor, asset and amount is stored | |
} | |
public entry fun colatarize_asset(depositor: &signer, asset: vector<u8>, amount: u64) { | |
let resource_account = get_resource_account_address(); | |
// TODO: How to get Coin type for the tranfer function | |
coint::transfer<HowToGetCoinType>( | |
depositor, | |
resource_account, | |
amount | |
); | |
let at_price = get_asset_price_with_pyth(&asset); | |
let depositor_address = signer::address_of(depositor): | |
add_colateral_record_to_state<Asset>(depositor_address, &asset, amount, at_price); | |
} | |
fun get_asset_price_with_pyth(asset: &vector<u8>): Price | |
fun add_colateral_record_to_state<Asset>(depositor_address: address, asset: &vector<u8>, anount: u64, at_price: Price) acquires State; | |
fun get_resource_account_address(): address; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment