Smart Contract

ceUSDT

A.231cc0dbbcffc4b7.ceUSDT

Deployed

1w ago
Feb 15, 2026, 04:38:48 AM UTC

Dependents

123 imports
1/// Canonical ceUSDT on Flow
2import FungibleToken from 0xf233dcee88fe0abe
3import FungibleTokenMetadataViews from 0xf233dcee88fe0abe
4import FTMinterBurner from 0x08dd120226ec2213
5
6access(all) contract ceUSDT: FungibleToken, FTMinterBurner {
7    // path for admin resource
8    access(all) let AdminPath: StoragePath
9    /// Total supply of tokens in existence, initial 0, and increase when new tokens are minted
10    access(all) var totalSupply: UFix64
11
12    /// TokensInitialized
13    ///
14    /// The event that is emitted when the contract is created
15    access(all) event TokensInitialized(initialSupply: UFix64)
16
17    /// TokensWithdrawn
18    ///
19    /// The event that is emitted when tokens are withdrawn from a Vault
20    access(all) event TokensWithdrawn(amount: UFix64, from: Address?)
21
22    /// TokensDeposited
23    ///
24    /// The event that is emitted when tokens are deposited to a Vault
25    access(all) event TokensDeposited(amount: UFix64, to: Address?)
26
27    /// TokensMinted
28    ///
29    /// The event that is emitted when new tokens are minted
30    access(all) event TokensMinted(amount: UFix64)
31
32    /// TokensBurned
33    ///
34    /// The event that is emitted when tokens are destroyed
35    access(all) event TokensBurned(amount: UFix64)
36
37    /// MinterCreated
38    ///
39    /// The event that is emitted when a new minter resource is created
40    access(all) event MinterCreated(allowedAmount: UFix64)
41
42    /// BurnerCreated
43    ///
44    /// The event that is emitted when a new burner resource is created
45    access(all) event BurnerCreated()
46
47    access(all) view fun getContractViews(resourceType: Type?): [Type] {
48        return [Type<FungibleTokenMetadataViews.FTVaultData>()]
49    }
50
51    access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
52        switch viewType {
53            case Type<FungibleTokenMetadataViews.FTVaultData>():
54                return FungibleTokenMetadataViews.FTVaultData(
55                    storagePath: /storage/ceUSDTVault,
56                    receiverPath: /public/ceUSDTVault,
57                    metadataPath: /public/ceUSDTReceiver,
58                    receiverLinkedType: Type<&ceUSDT.Vault>(),
59                    metadataLinkedType: Type<&ceUSDT.Vault>(),
60                    createEmptyVaultFunction: (fun(): @{FungibleToken.Vault} {
61                        return <-self.createEmptyVault(vaultType: Type<@ceUSDT.Vault>())
62                    })
63                )
64        }
65        return nil
66    }
67
68    /// Vault
69    ///
70    /// Each user stores an instance of only the Vault in their storage
71    /// The functions in the Vault and governed by the pre and post conditions
72    /// in FungibleToken when they are called.
73    /// The checks happen at runtime whenever a function is called.
74    ///
75    /// Resources can only be created in the context of the contract that they
76    /// are defined in, so there is no way for a malicious user to create Vaults
77    /// out of thin air. A special Minter resource needs to be defined to mint
78    /// new tokens.
79    ///
80    access(all) resource Vault: FungibleToken.Vault {
81
82        /// The total balance of this vault
83        access(all) var balance: UFix64
84
85        // initialize the balance at resource creation time
86        init(balance: UFix64) {
87            self.balance = balance
88        }
89
90        /// withdraw
91        ///
92        /// Function that takes an amount as an argument
93        /// and withdraws that amount from the Vault.
94        ///
95        /// It creates a new temporary Vault that is used to hold
96        /// the money that is being transferred. It returns the newly
97        /// created Vault to the context that called so it can be deposited
98        /// elsewhere.
99        ///
100        access(FungibleToken.Withdraw) fun withdraw(amount: UFix64): @{FungibleToken.Vault} {
101            self.balance = self.balance - amount
102            emit TokensWithdrawn(amount: amount, from: self.owner?.address)
103            return <-create Vault(balance: amount)
104        }
105
106        /// deposit
107        ///
108        /// Function that takes a Vault object as an argument and adds
109        /// its balance to the balance of the owners Vault.
110        ///
111        /// It is allowed to destroy the sent Vault because the Vault
112        /// was a temporary holder of the tokens. The Vault's balance has
113        /// been consumed and therefore can be destroyed.
114        ///
115        access(all) fun deposit(from: @{FungibleToken.Vault}) {
116            let vault <- from as! @ceUSDT.Vault
117            self.balance = self.balance + vault.balance
118            emit TokensDeposited(amount: vault.balance, to: self.owner?.address)
119            vault.balance = 0.0
120            destroy vault
121        }
122
123        /// Called when a fungible token is burned via the `Burner.burn()` method
124        access(contract) fun burnCallback() {
125            if self.balance > 0.0 {
126                ceUSDT.totalSupply = ceUSDT.totalSupply - self.balance
127                self.balance = 0.0
128            }
129        }
130    
131        access(all) fun createEmptyVault(): @{FungibleToken.Vault} {
132            return <- create Vault(balance: 0.0)
133        }
134
135        access(all) view fun isAvailableToWithdraw(amount: UFix64): Bool {
136            return amount <= self.balance
137        }
138
139        access(all) view fun getViews(): [Type] {
140            return ceUSDT.getContractViews(resourceType: nil)
141        }
142
143        access(all) fun resolveView(_ view: Type): AnyStruct? {
144            return ceUSDT.resolveContractView(resourceType: nil, viewType: view)
145        }
146    }
147
148    /// createEmptyVault
149    ///
150    /// Function that creates a new Vault with a balance of zero
151    /// and returns it to the calling context. A user must call this function
152    /// and store the returned Vault in their storage in order to allow their
153    /// account to be able to receive deposits of this token type.
154    ///
155    access(all) fun createEmptyVault(vaultType: Type): @{FungibleToken.Vault} {
156        return <-create Vault(balance: 0.0)
157    }
158
159    access(all) resource Administrator {
160
161        /// createNewMinter
162        ///
163        /// Function that creates and returns a new minter resource
164        ///
165        access(all) fun createNewMinter(allowedAmount: UFix64): @{FTMinterBurner.Minter} {
166            emit MinterCreated(allowedAmount: allowedAmount)
167            return <-create Minter(allowedAmount: allowedAmount)
168        }
169
170        /// createNewBurner
171        ///
172        /// Function that creates and returns a new burner resource
173        ///
174        access(all) fun createNewBurner(): @{FTMinterBurner.Burner} {
175            emit BurnerCreated()
176            return <-create Burner()
177        }
178    }
179
180    /// Minter
181    ///
182    /// Resource object that token admin accounts can hold to mint new tokens.
183    ///
184    access(all) resource Minter: FTMinterBurner.Minter {
185
186        /// The amount of tokens that the minter is allowed to mint
187        access(all) var allowedAmount: UFix64
188
189        /// mintTokens
190        ///
191        /// Function that mints new tokens, adds them to the total supply,
192        /// and returns them to the calling context.
193        ///
194        access(all) fun mintTokens(amount: UFix64): @{FungibleToken.Vault} {
195            pre {
196                amount > 0.0: "Amount minted must be greater than zero"
197                amount <= self.allowedAmount: "Amount minted must be less than the allowed amount"
198            }
199            ceUSDT.totalSupply = ceUSDT.totalSupply + amount
200            self.allowedAmount = self.allowedAmount - amount
201            emit TokensMinted(amount: amount)
202            return <-create Vault(balance: amount)
203        }
204
205        init(allowedAmount: UFix64) {
206            self.allowedAmount = allowedAmount
207        }
208    }
209
210    /// Burner
211    ///
212    /// Resource object that token admin accounts can hold to burn tokens.
213    ///
214    access(all) resource Burner: FTMinterBurner.Burner {
215
216        /// burnTokens
217        ///
218        /// Function that destroys a Vault instance, effectively burning the tokens.
219        ///
220        /// Note: the burned tokens are automatically subtracted from the
221        /// total supply in the Vault destructor.
222        ///
223        access(all) fun burnTokens(from: @{FungibleToken.Vault}) {
224            let vault <- from as! @ceUSDT.Vault
225            let amount = vault.balance
226            destroy vault
227            emit TokensBurned(amount: amount)
228        }
229    }
230
231    init() {
232        self.totalSupply = 0.0
233
234        // account owner only has admin resource, no vault as tokens are only minted later
235        let admin <- create Administrator()
236        self.AdminPath = /storage/ceUSDTAdmin
237        self.account.storage.save(<-admin, to: self.AdminPath)
238
239        // Emit an event that shows that the contract was initialized
240        emit TokensInitialized(initialSupply: self.totalSupply)
241    }
242}