Created
October 12, 2021 18:25
-
-
Save DenisCarriere/17f072da5aa33aae182743a5a831bb00 to your computer and use it in GitHub Desktop.
Sell using Defibox multi-hop on incoming transfer
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
#include <eosio.token.hpp> | |
using namespace eosio; | |
static constexpr extended_symbol EOS{{"EOS", 4}, "eosio.token"_n }; | |
static constexpr extended_symbol USDT{{"USDT", 4}, "tethertether"_n }; | |
class [[eosio::contract]] defiboxsell : public contract { | |
public: | |
using contract::contract; | |
[[eosio::on_notify("eosio.token::transfer")]] | |
void on_transfer( const name from, const name to, const asset quantity, const std::string memo ) | |
{ | |
require_auth( from ); | |
if ( to != get_self() ) return; | |
// sell EOS=>PBTC on Defibox | |
const int64_t amount = quantity.amount; | |
transfer( get_self(), "swap.defi"_n, { amount, EOS }, "swap,0,177" ); | |
} | |
[[eosio::on_notify("tethertether::transfer")]] | |
void on_transfer( const name from, const name to, const asset quantity, const std::string memo ) | |
{ | |
require_auth( from ); | |
if ( to != get_self() ) return; | |
// sell USDT=>EOS=>PBTC on Defibox using multi-hop | |
const int64_t amount = quantity.amount; | |
transfer( get_self(), "swap.defi"_n, { amount, USDT }, "swap,0,12-177" ); | |
} | |
private: | |
void transfer( const name from, const name to, const extended_asset value, const std::string memo ) | |
{ | |
eosio::token::transfer_action transfer( value.contract, { from, "active"_n }); | |
transfer.send( from, to, value.quantity, memo ); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment