Skip to content

Instantly share code, notes, and snippets.

@DenisCarriere
Created October 12, 2021 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DenisCarriere/17f072da5aa33aae182743a5a831bb00 to your computer and use it in GitHub Desktop.
Save DenisCarriere/17f072da5aa33aae182743a5a831bb00 to your computer and use it in GitHub Desktop.
Sell using Defibox multi-hop on incoming transfer
#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