@@ -3,9 +3,9 @@ use pyth::ByteBuffer;
3
3
4
4
#[starknet:: interface]
5
5
pub trait ISendUsd <T > {
6
- /// Sends ETH from the caller to the destination. The amount of ETH will be equivalent
7
- /// to the specified amount of USD, converted using the last available ETH /USD price from Pyth.
8
- /// `price_update` should be the latest available price update for the ETH /USD price feed.
6
+ /// Sends STRK from the caller to the destination. The amount of STRK will be equivalent
7
+ /// to the specified amount of USD, converted using the last available STRK /USD price from Pyth.
8
+ /// `price_update` should be the latest available price update for the STRK /USD price feed.
9
9
/// The caller needs to set up sufficient allowance for this contract.
10
10
fn send_usd (
11
11
ref self : T , destination : ContractAddress , amount_in_usd : u256 , price_update : ByteBuffer
@@ -20,29 +20,23 @@ mod send_usd {
20
20
use openzeppelin :: token :: erc20 :: interface :: {IERC20CamelDispatcherTrait , IERC20CamelDispatcher };
21
21
22
22
const MAX_PRICE_AGE : u64 = 3600 ; // 1 hour
23
- const WEI_PER_ETH : u256 = 1000000000000000000 ;
23
+ const TOKENS_PER_STRK : u256 = 1000000000000000000 ;
24
24
25
25
#[storage]
26
26
struct Storage {
27
27
pyth_address : ContractAddress ,
28
- eth_erc20_address : ContractAddress ,
29
- eth_usd_price_id : u256 ,
28
+ strk_erc20_address : ContractAddress ,
30
29
}
31
30
32
31
/// Initializes the contract.
33
32
/// `pyth_address` is the address of the deployed Pyth account.
34
- /// `eth_erc20_address` is the address of the ERC20 token account for the ETH token.
35
- /// `eth_usd_price_id` is the ID of Pyth's price feed for ETH/USD.
33
+ /// `strk_erc20_address` is the address of the ERC20 token account for the STRK token.
36
34
#[constructor]
37
35
fn constructor (
38
- ref self : ContractState ,
39
- pyth_address : ContractAddress ,
40
- eth_erc20_address : ContractAddress ,
41
- eth_usd_price_id : u256 ,
36
+ ref self : ContractState , pyth_address : ContractAddress , strk_erc20_address : ContractAddress ,
42
37
) {
43
38
self . pyth_address. write (pyth_address );
44
- self . eth_erc20_address. write (eth_erc20_address );
45
- self . eth_usd_price_id. write (eth_usd_price_id );
39
+ self . strk_erc20_address. write (strk_erc20_address );
46
40
}
47
41
48
42
#[abi(embed_v0)]
@@ -54,34 +48,36 @@ mod send_usd {
54
48
price_update : ByteBuffer
55
49
) {
56
50
let pyth = IPythDispatcher { contract_address : self . pyth_address. read () };
57
- let eth_erc20 = IERC20CamelDispatcher {
58
- contract_address : self . eth_erc20_address . read ()
51
+ let strk_erc20 = IERC20CamelDispatcher {
52
+ contract_address : self . strk_erc20_address . read ()
59
53
};
60
54
let caller = get_caller_address ();
61
55
let contract = get_contract_address ();
62
56
63
- let pyth_fee = pyth . get_update_fee (price_update . clone (), eth_erc20 . contract_address);
64
- if ! eth_erc20 . transferFrom (caller , contract , pyth_fee ) {
57
+ let pyth_fee = pyth . get_update_fee (price_update . clone (), strk_erc20 . contract_address);
58
+ if ! strk_erc20 . transferFrom (caller , contract , pyth_fee ) {
65
59
panic_with_felt252 (' insufficient allowance for fee' );
66
60
}
67
- if ! eth_erc20 . approve (pyth . contract_address, pyth_fee ) {
61
+ if ! strk_erc20 . approve (pyth . contract_address, pyth_fee ) {
68
62
panic_with_felt252 (' approve failed' );
69
63
}
70
64
71
65
pyth . update_price_feeds (price_update );
72
66
67
+ /// `strk_usd_price_id` is the ID of Pyth's price feed for STRK/USD.
68
+ let strk_usd_price_id =
69
+ 0x6a182399ff70ccf3e06024898942028204125a819e519a335ffa4579e66cd870 ;
73
70
let price = pyth
74
- . get_price_no_older_than (self . eth_usd_price_id . read () , MAX_PRICE_AGE )
71
+ . get_price_no_older_than (strk_usd_price_id , MAX_PRICE_AGE )
75
72
. unwrap_with_felt252 ();
76
73
77
74
let price_u64 : u64 = price . price. try_into (). unwrap ();
78
- let amount_in_wei = WEI_PER_ETH
75
+ let amount_in_wei = TOKENS_PER_STRK
79
76
* exp10 ((- price . expo). try_into (). unwrap ())
80
77
* amount_in_usd
81
78
/ price_u64 . into ();
82
79
83
- let transfer_ok = eth_erc20
84
- . transferFrom (caller , destination , amount_in_wei );
80
+ let transfer_ok = strk_erc20 . transferFrom (caller , destination , amount_in_wei );
85
81
if ! transfer_ok {
86
82
panic_with_felt252 (' insufficient allowance' );
87
83
}
0 commit comments