Skip to content
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

[Feature] Multi Offer #135

Merged
merged 15 commits into from
Sep 23, 2022
2 changes: 1 addition & 1 deletion build/StarcoinFramework/BuildInfo.yaml
Original file line number Diff line number Diff line change
@@ -321,7 +321,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: 13FC950A2297D1DCC2299C8CD3C7893BFCEEFC2621ED17704FC096B8BBB270D0
source_digest: BD4698365192AD9803A95852FBFB630DC61D1AB93B344478059A6673F587B044
build_flags:
dev_mode: false
test_mode: false
Binary file modified build/StarcoinFramework/abis/Offer/take_offer.abi
Binary file not shown.
Binary file modified build/StarcoinFramework/bytecode_modules/Offer.mv
Binary file not shown.
231 changes: 24 additions & 207 deletions build/StarcoinFramework/docs/Offer.md
Original file line number Diff line number Diff line change
@@ -20,22 +20,17 @@
- [Function `address_of`](#0x1_Offer_address_of)
- [Function `address_of_v2`](#0x1_Offer_address_of_v2)
- [Function `retake`](#0x1_Offer_retake)
- [Function `retake_entry`](#0x1_Offer_retake_entry)
- [Function `retake_v2`](#0x1_Offer_retake_v2)
- [Function `retake_v2_entry`](#0x1_Offer_retake_v2_entry)
- [Function `get_offers_infos`](#0x1_Offer_get_offers_infos)
- [Function `get_offers_info`](#0x1_Offer_get_offers_info)
- [Function `unpack_Offer_info`](#0x1_Offer_unpack_Offer_info)
- [Function `unpack_offer_info`](#0x1_Offer_unpack_offer_info)
- [Function `get_offers_length`](#0x1_Offer_get_offers_length)
- [Function `is_offers_empty`](#0x1_Offer_is_offers_empty)
- [Function `take_offer`](#0x1_Offer_take_offer)
- [Function `take_offer_v2`](#0x1_Offer_take_offer_v2)
- [Function `take_offer_v2_entry`](#0x1_Offer_take_offer_v2_entry)
- [Function `find_offer`](#0x1_Offer_find_offer)
- [Module Specification](#@Module_Specification_1)


<pre><code><b>use</b> <a href="Collection2.md#0x1_Collection2">0x1::Collection2</a>;
<pre><code><b>use</b> <a href="Debug.md#0x1_Debug">0x1::Debug</a>;
<b>use</b> <a href="Errors.md#0x1_Errors">0x1::Errors</a>;
<b>use</b> <a href="Option.md#0x1_Option">0x1::Option</a>;
<b>use</b> <a href="Signer.md#0x1_Signer">0x1::Signer</a>;
@@ -215,6 +210,15 @@ Offer is not unlocked yet.



<a name="0x1_Offer_ERR_DEPRECATED"></a>



<pre><code><b>const</b> <a href="Offer.md#0x1_Offer_ERR_DEPRECATED">ERR_DEPRECATED</a>: u64 = 1;
</code></pre>



<a name="0x1_Offer_create"></a>

## Function `create`
@@ -702,7 +706,7 @@ Fails if no such <code><a href="Offer.md#0x1_Offer">Offer</a></code> exists.



<pre><code><b>public</b> <b>fun</b> <a href="Offer.md#0x1_Offer_retake">retake</a>&lt;Offered: store&gt;(account: &signer): Offered
<pre><code><b>public</b> <b>fun</b> <a href="Offer.md#0x1_Offer_retake">retake</a>&lt;Offered: store&gt;(account: &signer, idx: u64): Offered
</code></pre>


@@ -711,85 +715,9 @@ Fails if no such <code><a href="Offer.md#0x1_Offer">Offer</a></code> exists.
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="Offer.md#0x1_Offer_retake">retake</a>&lt;Offered: store&gt;(account: &signer): Offered <b>acquires</b> <a href="Offer.md#0x1_Offer">Offer</a> {
<pre><code><b>public</b> <b>fun</b> <a href="Offer.md#0x1_Offer_retake">retake</a>&lt;Offered: store&gt;(account: &signer, idx: u64): Offered <b>acquires</b> <a href="Offer.md#0x1_Offer">Offer</a>, <a href="Offer.md#0x1_Offer_Offers">Offers</a> {
<b>let</b> account_address = <a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(account);
<b>assert</b>!(<a href="Offer.md#0x1_Offer_exists_at">exists_at</a>&lt;Offered&gt;(account_address), <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Offer.md#0x1_Offer_EOFFER_NOT_HAVE_OFFER">EOFFER_NOT_HAVE_OFFER</a>));
<b>let</b> <a href="Offer.md#0x1_Offer">Offer</a>&lt;Offered&gt; { offered: offered, for: _, time_lock: _ } = <b>move_from</b>&lt;<a href="Offer.md#0x1_Offer">Offer</a>&lt;Offered&gt;&gt;(account_address);
offered
}
</code></pre>



</details>

<details>
<summary>Specification</summary>



<pre><code><b>pragma</b> verify = <b>false</b>;
</code></pre>



</details>

<a name="0x1_Offer_retake_entry"></a>

## Function `retake_entry`



<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="Offer.md#0x1_Offer_retake_entry">retake_entry</a>&lt;Offered: store&gt;(signer: signer)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> (<b>script</b>) <b>fun</b> <a href="Offer.md#0x1_Offer_retake_entry">retake_entry</a>&lt;Offered: store&gt;(signer: signer) <b>acquires</b> <a href="Offer.md#0x1_Offer">Offer</a> {
<b>let</b> offered = <a href="Offer.md#0x1_Offer_retake">retake</a>&lt;Offered&gt;(&signer);
<a href="Collection2.md#0x1_Collection2_put">Collection2::put</a>(&signer, <a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(&signer), offered);
}
</code></pre>



</details>

<details>
<summary>Specification</summary>



<pre><code><b>pragma</b> verify = <b>false</b>;
</code></pre>



</details>

<a name="0x1_Offer_retake_v2"></a>

## Function `retake_v2`



<pre><code><b>public</b> <b>fun</b> <a href="Offer.md#0x1_Offer_retake_v2">retake_v2</a>&lt;Offered: store&gt;(account: &signer, idx: u64): Offered
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="Offer.md#0x1_Offer_retake_v2">retake_v2</a>&lt;Offered: store&gt;(account: &signer, idx: u64): Offered <b>acquires</b> <a href="Offer.md#0x1_Offer">Offer</a>, <a href="Offer.md#0x1_Offer_Offers">Offers</a> {
<b>let</b> account_address = <a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(account);
<b>let</b> <a href="Offer.md#0x1_Offer">Offer</a>&lt;Offered&gt; { offered: offered, for: _, time_lock: _ } = <b>if</b>(<b>exists</b>&lt;<a href="Offer.md#0x1_Offer_Offers">Offers</a>&lt;Offered&gt;&gt;(account_address)){
<b>let</b> <a href="Offer.md#0x1_Offer">Offer</a>&lt;Offered&gt; { offered: offered, for: _, time_lock: time_lock } = <b>if</b>(<b>exists</b>&lt;<a href="Offer.md#0x1_Offer_Offers">Offers</a>&lt;Offered&gt;&gt;(account_address)){
<b>let</b> offers = &<b>mut</b> <b>borrow_global_mut</b>&lt;<a href="Offer.md#0x1_Offer_Offers">Offers</a>&lt;Offered&gt;&gt;(account_address).offers;
<b>assert</b>!(<a href="Vector.md#0x1_Vector_length">Vector::length</a>(offers) - 1 &gt;= idx, <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Offer.md#0x1_Offer_EOFFER_NOT_HAVE_OFFER">EOFFER_NOT_HAVE_OFFER</a>));
<b>let</b> offer = <a href="Vector.md#0x1_Vector_remove">Vector::remove</a>(offers, idx);
@@ -803,6 +731,9 @@ Fails if no such <code><a href="Offer.md#0x1_Offer">Offer</a></code> exists.
}<b>else</b>{
<b>abort</b> <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(<a href="Offer.md#0x1_Offer_EOFFER_NOT_HAVE_OFFER">EOFFER_NOT_HAVE_OFFER</a>)
};
<b>let</b> now = <a href="Timestamp.md#0x1_Timestamp_now_seconds">Timestamp::now_seconds</a>();
StarcoinFramework::Debug::print(&(time_lock + ( 3600 * 24 * 30 * 3)));
<b>assert</b>!(now &gt;= time_lock + ( 3600 * 24 * 30 ), <a href="Errors.md#0x1_Errors_not_published">Errors::not_published</a>(<a href="Offer.md#0x1_Offer_EOFFER_NOT_UNLOCKED">EOFFER_NOT_UNLOCKED</a>));
offered
}
</code></pre>
@@ -821,43 +752,6 @@ Fails if no such <code><a href="Offer.md#0x1_Offer">Offer</a></code> exists.



</details>

<a name="0x1_Offer_retake_v2_entry"></a>

## Function `retake_v2_entry`



<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="Offer.md#0x1_Offer_retake_v2_entry">retake_v2_entry</a>&lt;Offered: store&gt;(signer: signer, idx: u64)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> (<b>script</b>) <b>fun</b> <a href="Offer.md#0x1_Offer_retake_v2_entry">retake_v2_entry</a>&lt;Offered: store&gt;(signer: signer, idx: u64) <b>acquires</b> <a href="Offer.md#0x1_Offer">Offer</a>, <a href="Offer.md#0x1_Offer_Offers">Offers</a> {
<b>let</b> offered = <a href="Offer.md#0x1_Offer_retake_v2">retake_v2</a>&lt;Offered&gt;(&signer, idx);
<a href="Collection2.md#0x1_Collection2_put">Collection2::put</a>(&signer, <a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(&signer), offered);
}
</code></pre>



</details>

<details>
<summary>Specification</summary>



<pre><code><b>pragma</b> verify = <b>false</b>;
</code></pre>



</details>

<a name="0x1_Offer_get_offers_infos"></a>
@@ -948,13 +842,13 @@ Fails if no such <code><a href="Offer.md#0x1_Offer">Offer</a></code> exists.

</details>

<a name="0x1_Offer_unpack_Offer_info"></a>
<a name="0x1_Offer_unpack_offer_info"></a>

## Function `unpack_Offer_info`
## Function `unpack_offer_info`



<pre><code><b>public</b> <b>fun</b> <a href="Offer.md#0x1_Offer_unpack_Offer_info">unpack_Offer_info</a>(offer_info: <a href="Offer.md#0x1_Offer_OfferInfo">Offer::OfferInfo</a>): (<b>address</b>, u64)
<pre><code><b>public</b> <b>fun</b> <a href="Offer.md#0x1_Offer_unpack_offer_info">unpack_offer_info</a>(offer_info: <a href="Offer.md#0x1_Offer_OfferInfo">Offer::OfferInfo</a>): (<b>address</b>, u64)
</code></pre>


@@ -963,7 +857,7 @@ Fails if no such <code><a href="Offer.md#0x1_Offer">Offer</a></code> exists.
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="Offer.md#0x1_Offer_unpack_Offer_info">unpack_Offer_info</a>(offer_info: <a href="Offer.md#0x1_Offer_OfferInfo">OfferInfo</a>):(<b>address</b>, u64){
<pre><code><b>public</b> <b>fun</b> <a href="Offer.md#0x1_Offer_unpack_offer_info">unpack_offer_info</a>(offer_info: <a href="Offer.md#0x1_Offer_OfferInfo">OfferInfo</a>):(<b>address</b>, u64){
<b>let</b> <a href="Offer.md#0x1_Offer_OfferInfo">OfferInfo</a>{ for, time_lock } = offer_info;
( for, time_lock )
}
@@ -1070,84 +964,7 @@ Fails if no such <code><a href="Offer.md#0x1_Offer">Offer</a></code> exists.
Take Offer and put to signer's Collection<Offered>.


<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="Offer.md#0x1_Offer_take_offer">take_offer</a>&lt;Offered: store&gt;(signer: signer, offer_address: <b>address</b>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="Offer.md#0x1_Offer_take_offer">take_offer</a>&lt;Offered: store&gt;(
signer: signer,
offer_address: <b>address</b>,
) <b>acquires</b> <a href="Offer.md#0x1_Offer">Offer</a>, <a href="Offer.md#0x1_Offer_Offers">Offers</a> {
<b>let</b> offered = <a href="Offer.md#0x1_Offer_redeem">redeem</a>&lt;Offered&gt;(&signer, offer_address);
<a href="Collection2.md#0x1_Collection2_put">Collection2::put</a>(&signer, <a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(&signer), offered);
}
</code></pre>



</details>

<details>
<summary>Specification</summary>



<pre><code><b>pragma</b> verify = <b>false</b>;
</code></pre>



</details>

<a name="0x1_Offer_take_offer_v2"></a>

## Function `take_offer_v2`



<pre><code><b>public</b> <b>fun</b> <a href="Offer.md#0x1_Offer_take_offer_v2">take_offer_v2</a>&lt;Offered: store&gt;(signer: &signer, offer_address: <b>address</b>, idx: u64)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="Offer.md#0x1_Offer_take_offer_v2">take_offer_v2</a>&lt;Offered :store&gt;(signer: &signer, offer_address: <b>address</b>, idx: u64) <b>acquires</b> <a href="Offer.md#0x1_Offer">Offer</a>, <a href="Offer.md#0x1_Offer_Offers">Offers</a>{
<b>let</b> offered = <a href="Offer.md#0x1_Offer_redeem_v2">redeem_v2</a>&lt;Offered&gt;(signer, offer_address, idx);
<a href="Collection2.md#0x1_Collection2_put">Collection2::put</a>(signer, <a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(signer), offered);
}
</code></pre>



</details>

<details>
<summary>Specification</summary>



<pre><code><b>pragma</b> verify = <b>false</b>;
</code></pre>



</details>

<a name="0x1_Offer_take_offer_v2_entry"></a>

## Function `take_offer_v2_entry`



<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="Offer.md#0x1_Offer_take_offer_v2_entry">take_offer_v2_entry</a>&lt;Offered: store&gt;(signer: signer, offer_address: <b>address</b>, idx: u64)
<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="Offer.md#0x1_Offer_take_offer">take_offer</a>&lt;Offered: store&gt;(_signer: signer, _offer_address: <b>address</b>)
</code></pre>


@@ -1156,8 +973,8 @@ Take Offer and put to signer's Collection<Offered>.
<summary>Implementation</summary>


<pre><code><b>public</b> (<b>script</b>) <b>fun</b> <a href="Offer.md#0x1_Offer_take_offer_v2_entry">take_offer_v2_entry</a>&lt;Offered :store&gt;(signer: signer, offer_address: <b>address</b>, idx: u64) <b>acquires</b> <a href="Offer.md#0x1_Offer">Offer</a>, <a href="Offer.md#0x1_Offer_Offers">Offers</a>{
<a href="Offer.md#0x1_Offer_take_offer_v2">take_offer_v2</a>&lt;Offered&gt;(&signer, offer_address, idx);
<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="Offer.md#0x1_Offer_take_offer">take_offer</a>&lt;Offered: store&gt;(_signer: signer, _offer_address: <b>address</b>){
<b>abort</b> <a href="Errors.md#0x1_Errors_invalid_state">Errors::invalid_state</a>(<a href="Offer.md#0x1_Offer_ERR_DEPRECATED">ERR_DEPRECATED</a>)
}
</code></pre>

Binary file modified build/StarcoinFramework/source_maps/Offer.mvsm
Binary file not shown.
6 changes: 3 additions & 3 deletions integration-tests/offer/offer.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
processed 16 tasks
processed 17 tasks

task 4 'run'. lines 9-31:
{
@@ -78,8 +78,8 @@ task 14 'run'. lines 147-159:
"status": "Executed"
}

task 15 'run'. lines 161-175:
task 16 'run'. lines 163-177:
{
"gas_used": 168821,
"gas_used": 190683,
"status": "Executed"
}
8 changes: 5 additions & 3 deletions integration-tests/offer/offer.move
Original file line number Diff line number Diff line change
@@ -133,7 +133,7 @@ script {
let offers_length = Offer::get_offers_length<Token<STC>>(@alice);
assert!(Vector::length(&offer_infos) == 3, 102);
assert!(offers_length == 3,103);
let ( for, time_lock) = Offer::unpack_Offer_info(Vector::remove(&mut offer_infos, 0));
let ( for, time_lock) = Offer::unpack_offer_info(Vector::remove(&mut offer_infos, 0));
assert!(for == @bob, 104);
assert!(time_lock == 86410, 105);

@@ -157,6 +157,8 @@ script {
}
}
// check: EXECUTED

//# block --author alice --timestamp 5270415000

//# run --signers alice
script {
@@ -166,9 +168,9 @@ script {
use StarcoinFramework::STC::STC;

fun retake_offer(account: signer) {
let token = Offer::retake_v2<Token<STC>>(&account, 1);
let token = Offer::retake<Token<STC>>(&account, 1);
Account::deposit_to_self(&account, token);
let token = Offer::retake_v2<Token<STC>>(&account, 0);
let token = Offer::retake<Token<STC>>(&account, 0);
Account::deposit_to_self(&account, token);
}
}
Loading