Skip to content

Commit

Permalink
fix: quote
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv committed Mar 7, 2024
1 parent 962a73e commit 66c9e1a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion scripts/generate_sig.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

user_addr = 0x123
erc20_addr = 0x5
quote = 1221805004292776
quote = 591205338160899000000
max_validity = 1000
encoded_string = 724720344857006587549020016926517802128122613457935427138661
data = pedersen_hash(pedersen_hash(pedersen_hash(erc20_addr, quote), max_validity), encoded_string)
Expand Down
2 changes: 1 addition & 1 deletion src/naming/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ impl UtilsImpl of UtilsTrait {
fn get_altcoin_price(
self: @Naming::ContractState, altcoin_quote: Wad, domain_price_eth: Wad
) -> u256 {
(domain_price_eth / altcoin_quote).into()
(domain_price_eth * altcoin_quote).into()
}
}
58 changes: 29 additions & 29 deletions src/tests/naming/test_altcoin.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ fn test_convert_quote_to_eth() {

// User wants to buy a domain in STRK for one year
let domain_price_eth = Wad { val: 8999999999999875 };
// 1 STRK = 0,00522180500429277 ETH
let quote = Wad { val: 5221805004292776 };
// 1 ETH = 1591.2053381608991 STRK
let quote = Wad { val: 1591205338160899000000 };

assert(
UtilsImpl::get_altcoin_price(
@unsafe_state, quote, domain_price_eth
) == 1723541953903122668_u256,
) == 14320848043447892099_u256,
'Wrong altcoin price'
);
}
Expand All @@ -63,18 +63,18 @@ fn test_buy_domain_with_strk() {
identity.mint(id1);

// we check how much a domain costs
let quote = Wad { val: 5221805004292776};
let quote = Wad { val: 1591205338160899000000};
let (_, price_in_eth) = pricing.compute_buy_price(7, 365);
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote;
let price_in_strk: Wad = Wad { val: price_in_eth.low } * quote;

// we allow the naming to take our money
strk.approve(naming.contract_address, price_in_strk.into());

// we buy with no resolver, no sponsor, no discount and empty metadata
let max_validity = 1000;
let sig = (
0x2d46882b7601332cab0b45a44c5da71d7cb8698d2aaa3eee1c777430047b4b1,
0x2eaebd6d46827e5bb1fd5c1a96c85f5dfbf3b77df03627545594e695867348a
0x45bab8945c7ebe23192a98a496e1f13929ca8fc8edaf810212f0ee00aab9d1c,
0x17f03434193b85c7f24354e7de98e4a4bc1e5bd9d26021be3cb26b9c80b282c
);
naming
.altcoin_buy(
Expand Down Expand Up @@ -120,18 +120,18 @@ fn test_buy_domain_altcoin_quote_expired() {
identity.mint(id1);

// we check how much a domain costs
let quote = Wad { val: 5221805004292776};
let quote = Wad { val: 1591205338160899000000};
let (_, price_in_eth) = pricing.compute_buy_price(7, 365);
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote;
let price_in_strk: Wad = Wad { val: price_in_eth.low } * quote;

// we allow the naming to take our money
strk.approve(naming.contract_address, price_in_strk.into());

// we buy with no resolver, no sponsor, no discount and empty metadata
let max_validity = 1000;
let sig = (
0x2d46882b7601332cab0b45a44c5da71d7cb8698d2aaa3eee1c777430047b4b1,
0x2eaebd6d46827e5bb1fd5c1a96c85f5dfbf3b77df03627545594e695867348a
0x45bab8945c7ebe23192a98a496e1f13929ca8fc8edaf810212f0ee00aab9d1c,
0x17f03434193b85c7f24354e7de98e4a4bc1e5bd9d26021be3cb26b9c80b282c
);

// we try buying after the max_validity timestamp
Expand Down Expand Up @@ -174,18 +174,18 @@ fn test_buy_domain_altcoin_wrong_quote() {
identity.mint(id1);

// we check how much a domain costs
let quote = Wad { val: 5221805004292776};
let quote = Wad { val: 1591205338160899000000};
let (_, price_in_eth) = pricing.compute_buy_price(7, 365);
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote;
let price_in_strk: Wad = Wad { val: price_in_eth.low } * quote;

// we allow the naming to take our money
strk.approve(naming.contract_address, price_in_strk.into());

// we buy with no resolver, no sponsor, no discount and empty metadata
let max_validity = 1000;
let sig = (
0x2d46882b7601332cab0b45a44c5da71d7cb8698d2aaa3eee1c777430047b4b1,
0x2eaebd6d46827e5bb1fd5c1a96c85f5dfbf3b77df03627545594e695867348a
0x45bab8945c7ebe23192a98a496e1f13929ca8fc8edaf810212f0ee00aab9d1c,
0x17f03434193b85c7f24354e7de98e4a4bc1e5bd9d26021be3cb26b9c80b282c
);
// we try buying with a quote lower than the actual price
let lower_quote = Wad { val: 1};
Expand Down Expand Up @@ -225,18 +225,18 @@ fn test_renew_domain_with_strk() {
identity.mint(id1);

// we check how much a domain costs
let quote = Wad { val: 5221805004292776};
let quote = Wad { val: 1591205338160899000000};
let (_, price_in_eth) = pricing.compute_buy_price(7, 365);
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote;
let price_in_strk: Wad = Wad { val: price_in_eth.low } * quote;

// we allow the naming to take our money
strk.approve(naming.contract_address, price_in_strk.into());

// we buy with no resolver, no sponsor, no discount and empty metadata
let max_validity = 1000;
let sig = (
0x2d46882b7601332cab0b45a44c5da71d7cb8698d2aaa3eee1c777430047b4b1,
0x2eaebd6d46827e5bb1fd5c1a96c85f5dfbf3b77df03627545594e695867348a
0x45bab8945c7ebe23192a98a496e1f13929ca8fc8edaf810212f0ee00aab9d1c,
0x17f03434193b85c7f24354e7de98e4a4bc1e5bd9d26021be3cb26b9c80b282c
);
naming
.altcoin_buy(
Expand All @@ -260,18 +260,18 @@ fn test_renew_domain_with_strk() {
);

// we check how much a domain costs to renew
let quote = Wad { val: 1221805004292776};
let quote = Wad { val: 591205338160899000000};
let (_, price_in_eth) = pricing.compute_buy_price(7, 365);
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote;
let price_in_strk: Wad = Wad { val: price_in_eth.low } * quote;

// we allow the naming to take our money
strk.approve(naming.contract_address, price_in_strk.into());

// we renew with no sponsor, no discount and empty metadata
let max_validity = 1000;
let sig = (
0x42768490cdba55ef41ac540caab9a9ec4133b5d1f42289d2c32f5c1efc07f65,
0x15d56a36d5fa94dc183ef32f4f9bc3d7f0d4b68b8b07a4541cad11a8c9cf7f6
0x21e23b2bf772d9c088d99103daf233d279e08fd0cce6cd079c1daec5e8e0e99,
0x7b362f5fa5907fb805018de4361d42e887f62473d8fd84e0b207e4a9bc99aaa
);
naming
.altcoin_renew(
Expand Down Expand Up @@ -336,18 +336,18 @@ fn test_subscription_with_strk() {
identity.mint(id1);

// we check how much a domain costs
let quote = Wad { val: 5221805004292776};
let quote = Wad { val: 1591205338160899000000};
let (_, price_in_eth) = pricing.compute_buy_price(7, 365);
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote;
let price_in_strk: Wad = Wad { val: price_in_eth.low } * quote;

// we allow the naming to take our money
strk.approve(naming.contract_address, price_in_strk.into());

// we buy with no resolver, no sponsor, no discount and empty metadata
let max_validity = 1000;
let sig = (
0x2d46882b7601332cab0b45a44c5da71d7cb8698d2aaa3eee1c777430047b4b1,
0x2eaebd6d46827e5bb1fd5c1a96c85f5dfbf3b77df03627545594e695867348a
0x45bab8945c7ebe23192a98a496e1f13929ca8fc8edaf810212f0ee00aab9d1c,
0x17f03434193b85c7f24354e7de98e4a4bc1e5bd9d26021be3cb26b9c80b282c
);
naming
.altcoin_buy(
Expand All @@ -371,9 +371,9 @@ fn test_subscription_with_strk() {
);

// we check how much a domain costs to renew
let quote = Wad { val: 1221805004292776};
let quote = Wad { val: 591205338160899000000};
let (_, price_in_eth) = pricing.compute_buy_price(7, 365);
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote;
let price_in_strk: Wad = Wad { val: price_in_eth.low } * quote;

// we whitelist renewal contract
let renewal_contract = contract_address_const::<0x456>();
Expand Down

0 comments on commit 66c9e1a

Please sign in to comment.