@ubi.fun/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +10 -0
- package/README.md +279 -0
- package/dist/abi/AddressFeeSplitManager.d.cts +938 -0
- package/dist/abi/AddressFeeSplitManager.d.ts +939 -0
- package/dist/abi/AddressFeeSplitManager.d.ts.map +1 -0
- package/dist/abi/BidWall.d.cts +739 -0
- package/dist/abi/BidWall.d.ts +740 -0
- package/dist/abi/BidWall.d.ts.map +1 -0
- package/dist/abi/FairLaunch.d.cts +535 -0
- package/dist/abi/FairLaunch.d.ts +536 -0
- package/dist/abi/FairLaunch.d.ts.map +1 -0
- package/dist/abi/FeeEscrow.d.cts +281 -0
- package/dist/abi/FeeEscrow.d.ts +282 -0
- package/dist/abi/FeeEscrow.d.ts.map +1 -0
- package/dist/abi/Flaunch.d.cts +775 -0
- package/dist/abi/Flaunch.d.ts +776 -0
- package/dist/abi/Flaunch.d.ts.map +1 -0
- package/dist/abi/FlaunchPositionManager.d.cts +2170 -0
- package/dist/abi/FlaunchPositionManager.d.ts +2171 -0
- package/dist/abi/FlaunchPositionManager.d.ts.map +1 -0
- package/dist/abi/FlaunchZap.d.cts +300 -0
- package/dist/abi/FlaunchZap.d.ts +301 -0
- package/dist/abi/FlaunchZap.d.ts.map +1 -0
- package/dist/abi/InitialPrice.d.cts +252 -0
- package/dist/abi/InitialPrice.d.ts +253 -0
- package/dist/abi/InitialPrice.d.ts.map +1 -0
- package/dist/abi/Memecoin.d.cts +680 -0
- package/dist/abi/Memecoin.d.ts +681 -0
- package/dist/abi/Memecoin.d.ts.map +1 -0
- package/dist/abi/Multicall.d.cts +332 -0
- package/dist/abi/Multicall.d.ts +333 -0
- package/dist/abi/Multicall.d.ts.map +1 -0
- package/dist/abi/PoolManager.d.cts +1056 -0
- package/dist/abi/PoolManager.d.ts +1057 -0
- package/dist/abi/PoolManager.d.ts.map +1 -0
- package/dist/abi/PoolSwap.d.cts +89 -0
- package/dist/abi/PoolSwap.d.ts +90 -0
- package/dist/abi/PoolSwap.d.ts.map +1 -0
- package/dist/abi/Quoter.d.cts +485 -0
- package/dist/abi/Quoter.d.ts +486 -0
- package/dist/abi/Quoter.d.ts.map +1 -0
- package/dist/abi/ReferralEscrow.d.cts +459 -0
- package/dist/abi/ReferralEscrow.d.ts +460 -0
- package/dist/abi/ReferralEscrow.d.ts.map +1 -0
- package/dist/abi/TreasuryManager.d.cts +325 -0
- package/dist/abi/TreasuryManager.d.ts +326 -0
- package/dist/abi/TreasuryManager.d.ts.map +1 -0
- package/dist/abi/TreasuryManagerFactory.d.cts +433 -0
- package/dist/abi/TreasuryManagerFactory.d.ts +434 -0
- package/dist/abi/TreasuryManagerFactory.d.ts.map +1 -0
- package/dist/abi/UniversalRewardsDistributor.d.cts +191 -0
- package/dist/abi/UniversalRewardsDistributor.d.ts +192 -0
- package/dist/abi/UniversalRewardsDistributor.d.ts.map +1 -0
- package/dist/abi/XHandleClaims.d.cts +383 -0
- package/dist/abi/XHandleClaims.d.ts +384 -0
- package/dist/abi/XHandleClaims.d.ts.map +1 -0
- package/dist/abi/index.cjs +13541 -0
- package/dist/abi/index.cjs.map +1 -0
- package/dist/abi/index.d.cts +18 -0
- package/dist/abi/index.d.ts +19 -0
- package/dist/abi/index.d.ts.map +1 -0
- package/dist/abi/index.js +13522 -0
- package/dist/abi/index.js.map +1 -0
- package/dist/addresses/index.cjs +90 -0
- package/dist/addresses/index.cjs.map +1 -0
- package/dist/addresses/index.js +70 -0
- package/dist/addresses/index.js.map +1 -0
- package/dist/addresses.d.cts +48 -0
- package/dist/addresses.d.ts +49 -0
- package/dist/addresses.d.ts.map +1 -0
- package/dist/clients/BidWallClient.d.cts +44 -0
- package/dist/clients/BidWallClient.d.ts +45 -0
- package/dist/clients/BidWallClient.d.ts.map +1 -0
- package/dist/clients/FairLaunchClient.d.cts +47 -0
- package/dist/clients/FairLaunchClient.d.ts +48 -0
- package/dist/clients/FairLaunchClient.d.ts.map +1 -0
- package/dist/clients/FeeEscrowClient.d.cts +40 -0
- package/dist/clients/FeeEscrowClient.d.ts +41 -0
- package/dist/clients/FeeEscrowClient.d.ts.map +1 -0
- package/dist/clients/FlaunchClient.d.cts +35 -0
- package/dist/clients/FlaunchClient.d.ts +36 -0
- package/dist/clients/FlaunchClient.d.ts.map +1 -0
- package/dist/clients/FlaunchPositionManagerClient.d.cts +117 -0
- package/dist/clients/FlaunchPositionManagerClient.d.ts +118 -0
- package/dist/clients/FlaunchPositionManagerClient.d.ts.map +1 -0
- package/dist/clients/FlaunchZapClient.d.cts +127 -0
- package/dist/clients/FlaunchZapClient.d.ts +128 -0
- package/dist/clients/FlaunchZapClient.d.ts.map +1 -0
- package/dist/clients/InitialPriceClient.d.cts +32 -0
- package/dist/clients/InitialPriceClient.d.ts +33 -0
- package/dist/clients/InitialPriceClient.d.ts.map +1 -0
- package/dist/clients/MemecoinClient.d.cts +66 -0
- package/dist/clients/MemecoinClient.d.ts +67 -0
- package/dist/clients/MemecoinClient.d.ts.map +1 -0
- package/dist/clients/MulticallClient.d.cts +15 -0
- package/dist/clients/MulticallClient.d.ts +16 -0
- package/dist/clients/MulticallClient.d.ts.map +1 -0
- package/dist/clients/PoolManagerClient.d.cts +50 -0
- package/dist/clients/PoolManagerClient.d.ts +51 -0
- package/dist/clients/PoolManagerClient.d.ts.map +1 -0
- package/dist/clients/PoolSwapClient.d.cts +37 -0
- package/dist/clients/PoolSwapClient.d.ts +38 -0
- package/dist/clients/PoolSwapClient.d.ts.map +1 -0
- package/dist/clients/QuoterClient.d.cts +58 -0
- package/dist/clients/QuoterClient.d.ts +59 -0
- package/dist/clients/QuoterClient.d.ts.map +1 -0
- package/dist/clients/ReferralEscrowClient.d.cts +39 -0
- package/dist/clients/ReferralEscrowClient.d.ts +40 -0
- package/dist/clients/ReferralEscrowClient.d.ts.map +1 -0
- package/dist/clients/TreasuryManagerClient.d.cts +71 -0
- package/dist/clients/TreasuryManagerClient.d.ts +72 -0
- package/dist/clients/TreasuryManagerClient.d.ts.map +1 -0
- package/dist/clients/TreasuryManagerFactoryClient.d.cts +15 -0
- package/dist/clients/TreasuryManagerFactoryClient.d.ts +16 -0
- package/dist/clients/TreasuryManagerFactoryClient.d.ts.map +1 -0
- package/dist/clients/UniversalRewardsDistributorClient.d.cts +45 -0
- package/dist/clients/UniversalRewardsDistributorClient.d.ts +46 -0
- package/dist/clients/UniversalRewardsDistributorClient.d.ts.map +1 -0
- package/dist/clients/XHandleClaimsClient.d.cts +64 -0
- package/dist/clients/XHandleClaimsClient.d.ts +65 -0
- package/dist/clients/XHandleClaimsClient.d.ts.map +1 -0
- package/dist/helpers/chainIdToChain.d.cts +113 -0
- package/dist/helpers/chainIdToChain.d.ts +114 -0
- package/dist/helpers/chainIdToChain.d.ts.map +1 -0
- package/dist/helpers/hex.d.cts +3 -0
- package/dist/helpers/hex.d.ts +4 -0
- package/dist/helpers/hex.d.ts.map +1 -0
- package/dist/helpers/index.cjs +196 -0
- package/dist/helpers/index.cjs.map +1 -0
- package/dist/helpers/index.d.cts +3 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +184 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/ipfs.d.cts +56 -0
- package/dist/helpers/ipfs.d.ts +57 -0
- package/dist/helpers/ipfs.d.ts.map +1 -0
- package/dist/hooks/FlaunchPositionManagerHooks.d.cts +28 -0
- package/dist/hooks/FlaunchPositionManagerHooks.d.ts +29 -0
- package/dist/hooks/FlaunchPositionManagerHooks.d.ts.map +1 -0
- package/dist/hooks/index.cjs +73 -0
- package/dist/hooks/index.cjs.map +1 -0
- package/dist/hooks/index.d.cts +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +70 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.cjs +16808 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +31 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16718 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.cjs +2 -0
- package/dist/index.umd.cjs.map +1 -0
- package/dist/sdk/FlaunchSDK.d.cts +520 -0
- package/dist/sdk/FlaunchSDK.d.ts +521 -0
- package/dist/sdk/FlaunchSDK.d.ts.map +1 -0
- package/dist/sdk/calldata.d.cts +65 -0
- package/dist/sdk/calldata.d.ts +66 -0
- package/dist/sdk/calldata.d.ts.map +1 -0
- package/dist/sdk/drift.d.cts +20 -0
- package/dist/sdk/drift.d.ts +21 -0
- package/dist/sdk/drift.d.ts.map +1 -0
- package/dist/sdk/factory.d.cts +20 -0
- package/dist/sdk/factory.d.ts +21 -0
- package/dist/sdk/factory.d.ts.map +1 -0
- package/dist/types.d.cts +56 -0
- package/dist/types.d.ts +57 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/index.cjs +455 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +4 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +431 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/parseSwap.d.cts +45 -0
- package/dist/utils/parseSwap.d.ts +46 -0
- package/dist/utils/parseSwap.d.ts.map +1 -0
- package/dist/utils/slippage.d.cts +11 -0
- package/dist/utils/slippage.d.ts +12 -0
- package/dist/utils/slippage.d.ts.map +1 -0
- package/dist/utils/swap.d.cts +49 -0
- package/dist/utils/swap.d.ts +50 -0
- package/dist/utils/swap.d.ts.map +1 -0
- package/dist/utils/univ4.d.cts +78 -0
- package/dist/utils/univ4.d.ts +79 -0
- package/dist/utils/univ4.d.ts.map +1 -0
- package/package.json +161 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ubi.fun
|
|
4
|
+
Copyright (c) https://flaunch.gg/ (original Flaunch SDK this package is derived from)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
7
|
+
|
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
# ubi.fun SDK
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
|
|
5
|
+
A TypeScript SDK for the [ubi.fun](https://ubi.fun) protocol on [Arc](https://www.arc.network) (Circle's chain): launch coins, trade their Uniswap v4 USDC pools, and claim creator, referral, split, X-handle, and daily holder rewards.
|
|
6
|
+
|
|
7
|
+
Derived from the [Flaunch SDK](https://github.com/flayerlabs/flaunch-sdk) and reworked for the ubi.fun v5 contracts, where the cash asset is native USDC (6 decimals) rather than flETH.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- 🚀 Launch memecoins through FlaunchZap, the same one-transaction entry point the app uses
|
|
12
|
+
- 💱 Buy and sell coins through PoolSwap with a referrer address that earns you 5% of the swap fee
|
|
13
|
+
- 📊 Quotes from the V4Quoter, pool/tick reads, fair launch and bid wall positions
|
|
14
|
+
- 💰 Claims for every revenue leg: creator revenue, referral rewards, earnings splits, X-handle shares, and the daily USDC holder pool
|
|
15
|
+
- 🔗 Works on Arc mainnet (5042) and Arc testnet (5042002)
|
|
16
|
+
|
|
17
|
+
Protocol docs: [ubi.fun/docs/integrate](https://ubi.fun/docs/integrate/overview). If you are building an AI agent, the hosted MCP server at `https://api.ubi.fun/mcp` exposes the same surface without keys.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm add @ubi.fun/sdk
|
|
23
|
+
# or: npm install @ubi.fun/sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { createUbiSDK, arc } from "@ubi.fun/sdk";
|
|
30
|
+
import { createPublicClient, http } from "viem";
|
|
31
|
+
|
|
32
|
+
const publicClient = createPublicClient({
|
|
33
|
+
chain: arc,
|
|
34
|
+
transport: http("<ARC_RPC_URL>"),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const sdkRead = createUbiSDK({ publicClient });
|
|
38
|
+
|
|
39
|
+
const { symbol, name, image } = await sdkRead.getCoinMetadata(coinAddress);
|
|
40
|
+
const price = await sdkRead.coinPriceInUSDC(coinAddress);
|
|
41
|
+
const marketCap = await sdkRead.coinMarketCapInUSDC(coinAddress);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Amounts follow the chain: **USDC is 6 decimals, every coin is 18 decimals**. One Arc quirk to know: `msg.value` is the same USDC at 18 decimals; the SDK computes any required transaction value for you.
|
|
45
|
+
|
|
46
|
+
### Write operations (Viem + Wagmi)
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { createUbiSDK, ReadWriteUbiSDK } from "@ubi.fun/sdk";
|
|
50
|
+
import { useWalletClient } from "wagmi";
|
|
51
|
+
import { useMemo } from "react";
|
|
52
|
+
|
|
53
|
+
const { data: walletClient } = useWalletClient();
|
|
54
|
+
|
|
55
|
+
const sdkWrite = useMemo(() => {
|
|
56
|
+
if (!publicClient || !walletClient) return null;
|
|
57
|
+
|
|
58
|
+
return createUbiSDK({
|
|
59
|
+
publicClient,
|
|
60
|
+
walletClient,
|
|
61
|
+
}) as ReadWriteUbiSDK;
|
|
62
|
+
}, [publicClient, walletClient]);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Launching a coin
|
|
66
|
+
|
|
67
|
+
Launches at the minimum $10,000 initial market cap are currently fee-free (gas only). Fair launch is optional: the chosen percent of supply sells at a fixed price for the chosen duration before normal trading starts.
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
const hash = await sdkWrite.createUBIIPFS({
|
|
71
|
+
name: "Test",
|
|
72
|
+
symbol: "TEST",
|
|
73
|
+
fairLaunchPercent: 40,
|
|
74
|
+
fairLaunchDuration: 30 * 60, // seconds
|
|
75
|
+
initialMarketCapUSD: 10_000,
|
|
76
|
+
creator: address, // receives the Flaunch NFT = the revenue claim
|
|
77
|
+
creatorFeeAllocationPercent: 90, // creator vs floor-bid split, app default 90
|
|
78
|
+
metadata: {
|
|
79
|
+
base64Image: imageData,
|
|
80
|
+
description: "Your memecoin description",
|
|
81
|
+
// optional: websiteUrl, discordUrl, twitterUrl, telegramUrl
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// parse the receipt for the coin address and NFT tokenId
|
|
86
|
+
const poolCreated = await sdkRead.getPoolCreatedFromTx(hash);
|
|
87
|
+
if (poolCreated) {
|
|
88
|
+
console.log("Coin:", poolCreated.memecoin, "tokenId:", poolCreated.tokenId);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`createUBIIPFS` pins the image and metadata through the ubi.fun API (IP rate limited, 5MB image cap).
|
|
93
|
+
|
|
94
|
+
To host metadata yourself, on any provider or your own storage, skip the IPFS helpers entirely: upload however you like, then pass the resulting URI to `createUBI({ tokenUri, ... })`. That is the provider neutral route and it keeps any storage credentials on your side rather than in the browser.
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
const tokenUri = await yourUploader(image, metadata); // ipfs://..., https://..., anything
|
|
98
|
+
const hash = await sdk.createUBI({ name, symbol, tokenUri, creator, ... });
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Earnings splits (and X handles)
|
|
102
|
+
|
|
103
|
+
Route parts of the creator revenue to other addresses, fixed at launch. The creator automatically keeps the exact remainder. A recipient can be the escrow of an X handle that has not even claimed yet:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
const escrow = await sdkRead.readXHandleClaims.escrowAddress("@friend");
|
|
107
|
+
|
|
108
|
+
await sdkWrite.createUBIIPFSWithSplitManager({
|
|
109
|
+
// ...same launch params as above...
|
|
110
|
+
splitReceivers: [
|
|
111
|
+
{ address: "0x123...", percent: 30 },
|
|
112
|
+
{ address: escrow, percent: 10 }, // @friend claims after verifying on ubi.fun
|
|
113
|
+
],
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Note: split launches deposit the revenue NFT into the split manager escrow, so "the NFT stays in your wallet" only holds for non-split launches.
|
|
118
|
+
|
|
119
|
+
## Trading
|
|
120
|
+
|
|
121
|
+
Approve the input token to PoolSwap once (USDC for buys, the coin for sells), then swap. **Always pass your address as `referrer`: 5% of the swap fee accrues to it on-chain.**
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { USDC_ADDRESS } from "@ubi.fun/sdk";
|
|
125
|
+
import { parseUnits, parseEther } from "viem";
|
|
126
|
+
|
|
127
|
+
// buy with 100 USDC
|
|
128
|
+
const amountIn = parseUnits("100", 6);
|
|
129
|
+
if ((await sdkWrite.swapAllowance(USDC_ADDRESS)) < amountIn) {
|
|
130
|
+
await sdkWrite.approveSwapInput(USDC_ADDRESS, amountIn);
|
|
131
|
+
}
|
|
132
|
+
const hash = await sdkWrite.buyCoin({
|
|
133
|
+
coinAddress,
|
|
134
|
+
amountIn,
|
|
135
|
+
slippagePercent: 5,
|
|
136
|
+
referrer: myAddress,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// sell 1M coins
|
|
140
|
+
const sellIn = parseEther("1000000");
|
|
141
|
+
if ((await sdkWrite.swapAllowance(coinAddress)) < sellIn) {
|
|
142
|
+
await sdkWrite.approveSwapInput(coinAddress, sellIn);
|
|
143
|
+
}
|
|
144
|
+
await sdkWrite.sellCoin({
|
|
145
|
+
coinAddress,
|
|
146
|
+
amountIn: sellIn,
|
|
147
|
+
slippagePercent: 5,
|
|
148
|
+
referrer: myAddress,
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Quotes
|
|
153
|
+
|
|
154
|
+
Use the same referrer in the quote and the swap, or they will not match:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
const coinsOut = await sdkRead.getBuyQuoteExactInput({
|
|
158
|
+
coinAddress,
|
|
159
|
+
amountIn: parseUnits("100", 6), // USDC in
|
|
160
|
+
referrer: myAddress,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const usdcOut = await sdkRead.getSellQuoteExactInput({
|
|
164
|
+
coinAddress,
|
|
165
|
+
amountIn: parseEther("1000000"), // coins in
|
|
166
|
+
referrer: myAddress,
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Claims
|
|
171
|
+
|
|
172
|
+
Everything pays out in USDC.
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
// creator revenue (accrues in the FeeEscrow, follows the Flaunch NFT)
|
|
176
|
+
const balance = await sdkRead.creatorRevenue(myAddress);
|
|
177
|
+
await sdkWrite.withdrawCreatorRevenue();
|
|
178
|
+
|
|
179
|
+
// referral rewards (accrue in the OUTPUT token of each swap you routed:
|
|
180
|
+
// buys accrue the coin, sells accrue USDC)
|
|
181
|
+
const owed = await sdkRead.referralBalance(myAddress, USDC_ADDRESS);
|
|
182
|
+
await sdkWrite.claimReferralBalance([USDC_ADDRESS, coinAddress], myAddress);
|
|
183
|
+
|
|
184
|
+
// earnings-split share (managerAddress from the launch's deployedManager)
|
|
185
|
+
const share = await sdkRead.splitBalance(managerAddress, myAddress);
|
|
186
|
+
await sdkWrite.claimSplitEarnings(managerAddress);
|
|
187
|
+
|
|
188
|
+
// daily holder pool (24% of every swap fee, split across coin holders daily;
|
|
189
|
+
// entitlement + Merkle proof come from the ubi.fun API)
|
|
190
|
+
const { claimable } = await sdkRead.claimableUbi(myAddress);
|
|
191
|
+
if (claimable > 0n) {
|
|
192
|
+
await sdkWrite.claimUbi();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// X-handle share: after verifying the handle through the ubi.fun OAuth flow
|
|
196
|
+
// (which submits the on-chain bind), pull the share to the bound wallet
|
|
197
|
+
await sdkWrite.readWriteXHandleClaims.claim("@myhandle", managerAddress);
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Watching events
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
const { cleanup } = await sdkRead.watchPoolCreated({
|
|
204
|
+
onPoolCreated: ({ logs }) => console.log(logs),
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const swaps = await sdkRead.watchPoolSwap({
|
|
208
|
+
onPoolSwap: ({ logs }) => console.log(logs), // typed BUY/SELL with USDC/coin deltas
|
|
209
|
+
filterByCoin: coinAddress,
|
|
210
|
+
});
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
React hooks are available from the `hooks` subpath:
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
import { usePoolCreatedEvents, usePoolSwapEvents } from "@ubi.fun/sdk/hooks";
|
|
217
|
+
|
|
218
|
+
const { logs: poolCreatedLogs } = usePoolCreatedEvents(sdkRead);
|
|
219
|
+
const { logs: poolSwapLogs } = usePoolSwapEvents(sdkRead, coinAddress);
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## `createUBICalldata`: calldata instead of broadcasting
|
|
223
|
+
|
|
224
|
+
For custom signers, account abstraction, or batching, `createUBICalldata` returns `{ to, value, data }` call objects instead of sending transactions:
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
import { createUBICalldata, parseCall } from "@ubi.fun/sdk";
|
|
228
|
+
|
|
229
|
+
const sdkCalldata = createUBICalldata({ publicClient, walletAddress });
|
|
230
|
+
|
|
231
|
+
const call = await parseCall(() =>
|
|
232
|
+
sdkCalldata.buyCoin({ coinAddress, amountIn, referrer })
|
|
233
|
+
);
|
|
234
|
+
// call.to, call.value, call.data
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Fetching coin metadata from a server
|
|
238
|
+
|
|
239
|
+
`getCoinMetadata`, `getCoinMetadataFromTokenId`, and `getCoinMetadataFromTokenIds` fetch a coin's `tokenURI` over HTTP. The SDK applies a 15 second timeout, a 3 redirect cap, a 5MB response cap, and rejects non HTTP(S) protocols.
|
|
240
|
+
|
|
241
|
+
A coin's `tokenURI` is arbitrary onchain data that anyone can set when launching. In the browser this is harmless because requests are CORS and sandbox gated. On a server it is not: the URL can point at private or link local addresses that your server can reach, which is a server side request forgery risk.
|
|
242
|
+
|
|
243
|
+
If you call these methods from a server against coins you do not control, put the fetch behind your own egress policy. Two options:
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
// 1. Point the resolver at a gateway or proxy you control
|
|
247
|
+
sdkRead.setIPFSResolver((value) =>
|
|
248
|
+
value.startsWith("ipfs://")
|
|
249
|
+
? `https://your-gateway.example/ipfs/${value.slice(7)}`
|
|
250
|
+
: value
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
// 2. Or read the tokenURI yourself and fetch it under your own policy
|
|
254
|
+
import { MemecoinAbi } from "@ubi.fun/sdk/abi";
|
|
255
|
+
|
|
256
|
+
const tokenURI = await publicClient.readContract({
|
|
257
|
+
address: coinAddress,
|
|
258
|
+
abi: MemecoinAbi,
|
|
259
|
+
functionName: "tokenURI",
|
|
260
|
+
});
|
|
261
|
+
const metadata = await yourVettedFetch(tokenURI);
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
For untrusted input, validate the resolved address against your blocklist before connecting, or route the request through a proxy restricted to public destinations.
|
|
265
|
+
|
|
266
|
+
## Naming: ubi vs Flaunch
|
|
267
|
+
|
|
268
|
+
The protocol is a fork of [Flaunch](https://flaunch.gg), and the deployed contracts keep the upstream names (`FlaunchPositionManager`, `Flaunched` events, and so on). The SDK therefore exposes both: the branded names used in this README (`createUbiSDK`, `ReadUbiSDK`, `ReadWriteUbiSDK`, `createUBI*`, `createUBICalldata`) and the upstream originals (`createFlaunch`, `ReadFlaunchSDK`, `ReadWriteFlaunchSDK`, `flaunch*`, `createFlaunchCalldata`). Each pair is the same object, so use whichever matches your mental model; the Flaunch names line up 1:1 with what you see on the block explorer.
|
|
269
|
+
|
|
270
|
+
## All SDK functions
|
|
271
|
+
|
|
272
|
+
For a list of all the functions in the SDK, refer to: [FlaunchSDK.ts](./src/sdk/FlaunchSDK.ts)
|
|
273
|
+
|
|
274
|
+
## Reference
|
|
275
|
+
|
|
276
|
+
- Protocol docs: [ubi.fun/docs](https://ubi.fun/docs/integrate/overview)
|
|
277
|
+
- Contract addresses ship in [`src/addresses.ts`](./src/addresses.ts) for Arc mainnet (5042) and testnet (5042002)
|
|
278
|
+
- REST data API: [ubi.fun/docs/integrate/api](https://ubi.fun/docs/integrate/api)
|
|
279
|
+
- MCP server for agents: [ubi.fun/docs/integrate/agents](https://ubi.fun/docs/integrate/agents)
|