
# USDC

CCTP là phương pháp được ưa thích để khai thác USDC nguyên thủy trên Hyperliquid L1. Xem <https://github.com/circlefin/hyperevm-circle-contracts> cho các hợp đồng và dòng chảy được công bố của Circle.

### Cầu thừa kế {#legacy-bridge}

CCTP hỗ trợ nhiều chuỗi và chức năng hơn. Cầu kế thừa đã lạc hậu.

Hợp đồng: <https://arbiscan.io/address/0x2df1c51e09aecf9cacb7bc98cb1742757f163df7>

Nguồn: <https://github.com/hyperliquid-dex/contracts/blob/master/Bridge2.sol>

#### Lưu ký {#deposit}

Luồng tiền gửi cho cầu nối rất đơn giản. Người sử dụng gửi USDC gốc đến cầu nối, và được ghi có vào tài khoản đã gửi nó trong ít hơn phút 1. Số tiền gửi tối thiểu là 5 USDC. Nếu bạn gửi ít hơn số này, nó sẽ không được ghi có và sẽ mất vĩnh viễn. &#x20;

#### Rút {#withdraw}

Luồng rút tiền chỉ yêu cầu chữ ký ví người dùng trên Hyperliquid, và không có giao dịch Arbitrum. Việc rút tiền từ Arbitrum được xử lý hoàn toàn bởi các trình xác thực, và các quỹ sẽ đến ví người dùng trong các phút 3-4. Trọng tải này cho signTypedData là

```rust
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
pub(crate) struct WithdrawAction3 {
    pub(crate) signature_chain_id: U256,
    pub(crate) hyperliquid_chain: Chain,
    pub(crate) destination: String,
    pub(crate) amount: String,
    pub(crate) time: u64,
}

impl Eip712 for WithdrawAction3 {
    type Error = Eip712Error;

    fn domain(&self) -> StdResult<EIP712Domain, Self::Error> {
        Ok(eip_712_domain(self.signature_chain_id))
    }

    fn type_hash() -> StdResult<[u8; 32], Self::Error> {
        Ok(eip712::make_type_hash(
            format!("{HYPERLIQUID_EIP_PREFIX}Withdraw"),
            &[
                ("hyperliquidChain".to_string(), ParamType::String),
                ("destination".to_string(), ParamType::String),
                ("amount".to_string(), ParamType::String),
                ("time".to_string(), ParamType::Uint(64)),
            ],
        ))
    }

    fn struct_hash(&self) -> StdResult<[u8; 32], Self::Error> {
        let Self { signature_chain_id: _, hyperliquid_chain, destination, amount, time } = self;
        let items = vec![
            ethers::abi::Token::Uint(Self::type_hash()?.into()),
            encode_eip712_type(hyperliquid_chain.to_string().into_token()),
            encode_eip712_type(destination.clone().into_token()),
            encode_eip712_type(amount.clone().into_token()),
            encode_eip712_type(time.into_token()),
        ];
        Ok(keccak256(encode(&items)))
    }
}
```

Ví dụ về hành động Hyperliquid đã ký:

```json
{
    "action": {
        "type": "withdraw3",
        "signatureChainId": "0xa4b1",
        "hyperliquidChain": "Mainnet" or "Testnet" 
        "destination": "0x000....0",
        "amount": "12.3",
        "time": 1698693262
    },
    "nonce": 1698693262 // IMPORTANT: this must match "time",
    "signature": {"r": ..., "s": ..., "v": ... } // signedTypedData output based on Eip712 implementation above. See python sdk for equivalent python code
}
```

#### Ký quỹ với giấy phép {#deposit-with-permit}

Cây cầu hỗ trợ gửi tiền thay mặt cho người dùng khác thông qua chức năng `batchedDepositWithPermit`.Mã ví dụ về cách người dùng có thể ký vào PermitPayload

```typescript
const payload: PermitPayload = {
  owner, // The address of the user with funds they want to deposit
  spender, // The address of the bridge 0x2df1c51e09aecf9cacb7bc98cb1742757f163df7 on mainnet and 0x08cfc1B6b2dCF36A1480b99353A354AA8AC56f89 on testnet
  value,
  nonce,
  deadline,
};

const isMainnet = true;

const domain = {
  name: isMainnet ? "USD Coin" : "USDC2",
  version: isMainnet ? "2" : "1",
  chainId: isMainnet ? 42161 : 421614,
  verifyingContract: isMainnet ? "0xaf88d065e77c8cC2239327C5EDb3A432268e5831" : "0x1baAbB04529D43a73232B713C0FE471f7c7334d5",
};

const permitTypes = {
  Permit: [
    { name: "owner", type: "address" },
    { name: "spender", type: "address" },
    { name: "value", type: "uint256" },
    { name: "nonce", type: "uint256" },
    { name: "deadline", type: "uint256" },
  ],
};

const dataToSign = {
  domain,
  types: permitTypes,
  primaryType: "Permit",
  message: payload,
} as const;

const data = await walletClient.signTypedData(dataToSign);
const signature = splitSig(data);
```