Skip to content

Commit

Permalink
ft_watcher: token router parser
Browse files Browse the repository at this point in the history
Signed-off-by: bingyuyap <[email protected]>
  • Loading branch information
bingyuyap committed Jun 5, 2024
1 parent fc3e7a1 commit b19e05f
Show file tree
Hide file tree
Showing 16 changed files with 1,996 additions and 1,640 deletions.
78 changes: 52 additions & 26 deletions database/fast-transfer-schema.sql
Original file line number Diff line number Diff line change
@@ -1,39 +1,65 @@
DROP TABLE IF EXISTS market_orders;
DROP TABLE IF EXISTS fast_transfer_auctions;
DROP TABLE IF EXISTS fast_transfer_executions;
DROP TABLE IF EXISTS fast_transfer_settlements;
DROP TABLE IF EXISTS auction_logs;

DROP TYPE IF EXISTS FastTransferStatus;
DROP TYPE IF EXISTS FastTransferProtocol;

CREATE TYPE FastTransferProtocol AS ENUM ('cctp', 'local', 'none');
CREATE TYPE FastTransferStatus AS ENUM ('pending', 'no_offer', 'executed', 'settled');
CREATE TYPE FastTransferStatus AS ENUM ('pending', 'no_offer', 'executed', 'settled', 'auction');

CREATE TABLE fast_transfers (
fast_transfer_id VARCHAR(255) PRIMARY KEY,
fast_vaa_hash VARCHAR(255) NOT NULL,
-- Market Order tracks events of when fast market orders are
-- placed in the token router
CREATE TABLE market_orders (
fast_vaa_id VARCHAR(255) PRIMARY KEY,
fast_vaa_hash VARCHAR(255),
amount_in BIGINT,
min_amount_out BIGINT,
src_chain INTEGER,
dst_chain INTEGER,
sender VARCHAR(255),
redeemer VARCHAR(255),
market_order_tx_hash VARCHAR(255),
market_order_timestamp TIMESTAMP,
status FastTransferStatus NOT NULL DEFAULT 'pending'
);

-- Auction tracks the latest state of the auction.
-- It is created when the auction is created in the `placeInitialOfferCctp`
-- ix in the MatchingEngine contract.
CREATE TABLE fast_transfer_auctions (
fast_vaa_hash VARCHAR(255) PRIMARY KEY,
auction_pubkey VARCHAR(255),
amount BIGINT NOT NULL,
initial_offer_time TIMESTAMP,
src_chain INTEGER NOT NULL,
dst_chain INTEGER NOT NULL,
sender VARCHAR(255) NOT NULL,
redeemer VARCHAR(255) NOT NULL,
tx_hash VARCHAR(255) NOT NULL,
timestamp TIMESTAMP NOT NULL,
start_slot BIGINT NOT NULL,
-- auction end on this slot
end_slot BIGINT NOT NULL,
-- deadline to execute the auction (end_slot + grace_period)
deadline_slot BIGINT NOT NULL,
-- current best offers
initial_offer_tx_hash VARCHAR(255),
initial_offer_timestamp TIMESTAMP,
start_slot BIGINT,
end_slot BIGINT,
deadline_slot BIGINT,
best_offer_amount BIGINT,
best_offer_token VARCHAR(255),
-- Enum: cctp, local, wormhole
message_protocol FastTransferProtocol NOT NULL DEFAULT 'none',
cctp_domain INT NULL,
local_program_id VARCHAR(255) NULL,
-- execution data
status FastTransferStatus NOT NULL DEFAULT 'pending',
message_protocol FastTransferProtocol DEFAULT 'none',
cctp_domain INT,
local_program_id VARCHAR(255)
);

-- Execution is created when the execution is created in the `executeFastOrder`
-- ix in the MatchingEngine contract.
CREATE TABLE fast_transfer_executions (
fast_vaa_hash VARCHAR(255) PRIMARY KEY,
user_amount BIGINT,
penalty BIGINT,
execution_payer VARCHAR(255),
execution_tx_hash VARCHAR(255),
execution_slot BIGINT,
execution_time TIMESTAMP,
-- settle data
execution_time TIMESTAMP
);

-- Settlement is created when the settlement is created in the `settleFastTransfer`
-- ix in the MatchingEngine contract.
CREATE TABLE fast_transfer_settlements (
fast_transfer_id VARCHAR(255) PRIMARY KEY,
repayment BIGINT,
settle_payer VARCHAR(255),
settle_tx_hash VARCHAR(255),
Expand Down
Loading

0 comments on commit b19e05f

Please sign in to comment.