Skip to content

Instantly share code, notes, and snippets.

@goodylili
Created April 24, 2025 13:12
Show Gist options
  • Save goodylili/79638fd6ac86e85b5156a35e9923e2fa to your computer and use it in GitHub Desktop.
Save goodylili/79638fd6ac86e85b5156a35e9923e2fa to your computer and use it in GitHub Desktop.
Evacuate or Send a bunch of tokens to an address on Sui
module rendevous::evacuate;
use sui::coin:: Coin;
use sui::event;
/// Event for each evacuation.
public struct AirdropEvent has copy, drop {
recipient: address,
num_tokens: u64,
}
const E_LENGTH_MISMATCH: u64 = 0;
/// Transfers specific amounts from multiple coins to the `recipient` in a single transaction.
public entry fun evacuate_wallet<T: store>(
recipient: address,
mut coins: vector<Coin<T>>,
amounts: vector<u64>,
ctx: &mut TxContext,
) {
let num_coins = vector::length(&coins);
let num_amounts = vector::length(&amounts);
assert!(num_coins == num_amounts, E_LENGTH_MISMATCH);
let mut i = 0;
while (i < num_coins) {
let mut coin = vector::pop_back(&mut coins);
let amount = *vector::borrow(&amounts, i);
let portion = sui::coin::split(&mut coin, amount, ctx);
transfer::public_transfer(portion, recipient);
transfer::public_transfer(coin, recipient);
i = i + 1;
};
event::emit(AirdropEvent {
recipient,
num_tokens: num_coins,
});
vector::destroy_empty(coins);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment