Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions db/migrations/0026_tempo_workspace_ousd.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Make OUSD the default tip token for Tempo's own Slack workspace (T098H03GGE6) on mainnet.
UPDATE "workspace"
SET
"default_token_address" = '0x20c0000000000000000000006a37DA5C996874BE',
"updated_at" = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
WHERE "provider" = 'slack'
AND "provider_id" = 'T098H03GGE6'
AND "chain_id" = 4217;
14 changes: 10 additions & 4 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ export const api = new Hono<{
chainName: Tempo.getChainName(link.chain_id),
expiresAt: link.expires_at,
ok: true as const,
tokenAddress: Address.checksum(link.default_token_address ?? Tempo.addressLookup.pathUsd),
tokenAddress: Address.checksum(
link.default_token_address ?? Tempo.getDefaultTokenAddress(link.chain_id),
),
})
})
.post(
Expand Down Expand Up @@ -176,7 +178,9 @@ export const api = new Hono<{
expiresAt: link.access_key_expires_at,
keyAuthorization: body.keyAuthorization,
rootAddress: body.address,
tokenAddress: Address.checksum(link.default_token_address ?? Tempo.addressLookup.pathUsd),
tokenAddress: Address.checksum(
link.default_token_address ?? Tempo.getDefaultTokenAddress(link.chain_id),
),
})
const now = new Date().toISOString()
const existingAccount = await c.var.db
Expand Down Expand Up @@ -252,7 +256,9 @@ export const api = new Hono<{
.where(
'token_address',
'=',
Address.checksum(link.default_token_address ?? Tempo.addressLookup.pathUsd),
Address.checksum(
link.default_token_address ?? Tempo.getDefaultTokenAddress(link.chain_id),
),
)
.execute()
await c.var.db
Expand All @@ -274,7 +280,7 @@ export const api = new Hono<{
id: Nanoid.generate(),
revoked_at: null,
token_address: Address.checksum(
link.default_token_address ?? Tempo.addressLookup.pathUsd,
link.default_token_address ?? Tempo.getDefaultTokenAddress(link.chain_id),
),
updated_at: now,
})
Expand Down
11 changes: 7 additions & 4 deletions src/api.workers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ describe('/api/account/link/:token', () => {
accessKeyAddress: pending.accessKey.address,
accessKeyPublicKey: pending.accessKey.publicKey,
ok: true,
tokenAddress: Tempo.addressLookup.pathUsd,
tokenAddress: Tempo.getDefaultTokenAddress(pending.workspace.chain_id),
})
})

Expand Down Expand Up @@ -1906,7 +1906,8 @@ describe('/api/confirm/:token', () => {
recipientProviderUserId: 'twitter-confirm-recipient',
senderProviderUserId: 'twitter-confirm-sender',
source: 'mention',
tokenAddress: workspace.default_token_address ?? Tempo.addressLookup.pathUsd,
tokenAddress:
workspace.default_token_address ?? Tempo.getDefaultTokenAddress(workspace.chain_id),
workspaceId: workspace.id,
})

Expand Down Expand Up @@ -1973,7 +1974,8 @@ describe('/api/confirm/:token', () => {
recipientProviderUserId,
senderProviderUserId,
source: 'mention',
tokenAddress: workspace.default_token_address ?? Tempo.addressLookup.pathUsd,
tokenAddress:
workspace.default_token_address ?? Tempo.getDefaultTokenAddress(workspace.chain_id),
workspaceId: workspace.id,
} satisfies Confirmation.Payload
const token = await Confirmation.encrypt(env, payload)
Expand Down Expand Up @@ -3100,7 +3102,8 @@ async function signKeyAuthorization(
chainId: pending.workspace.chain_id,
expiresAt: pending.link.access_key_expires_at,
tokenAddress: Address.checksum(
pending.workspace.default_token_address ?? Tempo.addressLookup.pathUsd,
pending.workspace.default_token_address ??
Tempo.getDefaultTokenAddress(pending.workspace.chain_id),
),
})
}
Expand Down
65 changes: 45 additions & 20 deletions src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,8 @@ const actions = {
}

const reactionTipConfigs = await getReactionTipConfigs(DB.create(env.DB), workspace.id)
const tokenAddress = workspace.default_token_address ?? Tempo.addressLookup.pathUsd
const tokenAddress =
workspace.default_token_address ?? Tempo.getDefaultTokenAddress(workspace.chain_id)
const tokenOptions = workspaceTokenOptions(workspace.chain_id)
const tokenValue =
tokenOptions.find((option) => option.address.toLowerCase() === tokenAddress.toLowerCase())
Expand Down Expand Up @@ -1014,7 +1015,7 @@ const modalSubmits = {
if (!creator) return

const tokenAddress = Address.checksum(
workspace.default_token_address ?? Tempo.addressLookup.pathUsd,
workspace.default_token_address ?? Tempo.getDefaultTokenAddress(workspace.chain_id),
)
const balance = await Actions.token.getBalance(
createClient({
Expand Down Expand Up @@ -1167,7 +1168,8 @@ const modalSubmits = {
if (!installation) return

const now = new Date()
const tokenAddress = workspace.default_token_address ?? Tempo.addressLookup.pathUsd
const tokenAddress =
workspace.default_token_address ?? Tempo.getDefaultTokenAddress(workspace.chain_id)
const tipRaffle = {
chain_id: workspace.chain_id,
created_at: now.toISOString(),
Expand Down Expand Up @@ -1375,7 +1377,8 @@ const handlers = {
return
}

const tokenAddress = workspace.default_token_address ?? Tempo.addressLookup.pathUsd
const tokenAddress =
workspace.default_token_address ?? Tempo.getDefaultTokenAddress(workspace.chain_id)
const token = await Tapimo.getTokenMetadata(env, workspace.chain_id, tokenAddress)
if (!('openModal' in event)) {
await postPrivateReply(
Expand Down Expand Up @@ -1451,7 +1454,8 @@ const handlers = {
return
}

const tokenAddress = workspace.default_token_address ?? Tempo.addressLookup.pathUsd
const tokenAddress =
workspace.default_token_address ?? Tempo.getDefaultTokenAddress(workspace.chain_id)
const token = await Tapimo.getTokenMetadata(env, workspace.chain_id, tokenAddress)
if (!('openModal' in event)) return
await event.openModal(
Expand Down Expand Up @@ -1579,7 +1583,8 @@ const handlers = {
provider_id: ctx.provider.id,
provider_message_ts: 'pending',
requester_member_id: requester.memberId,
token_address: workspace.default_token_address ?? Tempo.addressLookup.pathUsd,
token_address:
workspace.default_token_address ?? Tempo.getDefaultTokenAddress(workspace.chain_id),
updated_at: now,
workspace_id: workspace.id,
} satisfies DB_gen.Insertable.tip_ask
Expand Down Expand Up @@ -2243,7 +2248,11 @@ const handlers = {
}

const tokenAddress = parsed.token
? Tempo.getTokenAddress(workspace?.chain_id ?? Tempo.chainLookup.mainnet, parsed.token)
? Tempo.getTokenAddress(
workspace?.chain_id ?? Tempo.chainLookup.mainnet,
parsed.token,
workspace?.default_token_address,
)
: null
if (parsed.token && !tokenAddress) {
await postPrivateReply(
Expand Down Expand Up @@ -2590,6 +2599,7 @@ const tipRaffleDurationOptions = [
{ label: '7 days', ms: 7 * 24 * 60 * 60 * 1000, value: '7d' }, // 7 days
] as const
const tokenOptions = [
{ address: Tempo.addressLookup.ousd, label: 'OUSD', value: 'OUSD' },
{ address: Tempo.addressLookup.pathUsd, label: 'PathUSD', value: 'pathUSD' },
{ address: Tempo.addressLookup.usdcE, label: 'USDC.e', value: 'USDC.e' },
{ address: Tempo.addressLookup.usdt0, label: 'USDT0', value: 'USDT0' },
Expand Down Expand Up @@ -4608,7 +4618,9 @@ async function sendTipRaffleEscrowPayout(
feePayer: 'sender',
isDefaultToken: Address.isEqual(
Address.checksum(existing.token_address),
Address.checksum(existing.default_token_address ?? Tempo.addressLookup.pathUsd),
Address.checksum(
existing.default_token_address ?? Tempo.getDefaultTokenAddress(existing.chain_id),
),
),
memo: existing.memo,
ok: true,
Expand Down Expand Up @@ -4745,7 +4757,9 @@ async function sendTipRaffleEscrowPayout(
feePayer: 'sender',
isDefaultToken: Address.isEqual(
Address.checksum(input.tokenAddress),
Address.checksum(workspace.default_token_address ?? Tempo.addressLookup.pathUsd),
Address.checksum(
workspace.default_token_address ?? Tempo.getDefaultTokenAddress(workspace.chain_id),
),
),
memo: input.memo,
ok: true,
Expand Down Expand Up @@ -4890,7 +4904,10 @@ async function tipRaffleMessage(db: DB.Type, tipRaffle: TipRaffleMessageInput) {
const value = formatAmount(amount)
return Address.isEqual(
Address.checksum(tipRaffle.token_address),
Address.checksum(tipRaffle.workspace_default_token_address ?? Tempo.addressLookup.pathUsd),
Address.checksum(
tipRaffle.workspace_default_token_address ??
Tempo.getDefaultTokenAddress(tipRaffle.chain_id),
),
)
? formatCurrencyAmount(value, token.currency)
: formatTipAmount(value, token.currency, token.symbol)
Expand Down Expand Up @@ -4997,7 +5014,9 @@ async function tipAskMessage(db: DB.Type, tipAsk: TipAskMessageInput) {
const value = formatAmount(amount)
return Address.isEqual(
Address.checksum(tipAsk.token_address),
Address.checksum(tipAsk.workspace_default_token_address ?? Tempo.addressLookup.pathUsd),
Address.checksum(
tipAsk.workspace_default_token_address ?? Tempo.getDefaultTokenAddress(tipAsk.chain_id),
),
)
? formatCurrencyAmount(value, token.currency)
: formatTipAmount(value, token.currency, token.symbol)
Expand Down Expand Up @@ -5312,7 +5331,7 @@ export async function updateReceiptBoostAggregate(
const amount = formatAmount(group.amount)
const displayAmount = Address.isEqual(
Address.checksum(group.tokenAddress),
Address.checksum(group.defaultTokenAddress ?? Tempo.addressLookup.pathUsd),
Address.checksum(group.defaultTokenAddress ?? Tempo.getDefaultTokenAddress(group.chainId)),
)
? formatCurrencyAmount(amount, token.currency)
: formatTipAmount(amount, token.currency, token.symbol)
Expand Down Expand Up @@ -6056,7 +6075,9 @@ async function postConnectLink(event: TipEvent, ctx: HandlerContext) {
(row) =>
!row.token_address ||
row.token_address.toLowerCase() ===
(workspace.default_token_address ?? Tempo.addressLookup.pathUsd).toLowerCase(),
(
workspace.default_token_address ?? Tempo.getDefaultTokenAddress(workspace.chain_id)
).toLowerCase(),
)
if (accessKey && !ctx.forceConnectRefresh) {
await postPrivateReply(event, event.user, 'Already connected', { threadTs: ctx.threadTs })
Expand Down Expand Up @@ -6801,7 +6822,7 @@ async function reactionTipAggregateText(
const amount = formatAmount(row.amount)
const displayAmount = Address.isEqual(
Address.checksum(row.token_address),
Address.checksum(row.default_token_address ?? Tempo.addressLookup.pathUsd),
Address.checksum(row.default_token_address ?? Tempo.getDefaultTokenAddress(row.chain_id)),
)
? formatCurrencyAmount(amount, token.currency)
: formatTipAmount(amount, token.currency, token.symbol)
Expand All @@ -6819,7 +6840,7 @@ async function reactionTipAggregateText(
const amount = formatAmount(row.amount)
const displayAmount = Address.isEqual(
Address.checksum(row.token_address),
Address.checksum(row.default_token_address ?? Tempo.addressLookup.pathUsd),
Address.checksum(row.default_token_address ?? Tempo.getDefaultTokenAddress(row.chain_id)),
)
? formatCurrencyAmount(amount, token.currency)
: formatTipAmount(amount, token.currency, token.symbol)
Expand All @@ -6844,7 +6865,7 @@ async function reactionTipAggregateText(
const amount = formatAmount(row.amount)
const displayAmount = Address.isEqual(
Address.checksum(row.token_address),
Address.checksum(row.default_token_address ?? Tempo.addressLookup.pathUsd),
Address.checksum(row.default_token_address ?? Tempo.getDefaultTokenAddress(row.chain_id)),
)
? formatCurrencyAmount(amount, token.currency)
: formatTipAmount(amount, token.currency, token.symbol)
Expand Down Expand Up @@ -7036,7 +7057,9 @@ export async function updateSlackPendingTipMessage(db: DB.Type, result: Tip.Pend
.executeTakeFirst()
const amount = Address.isEqual(
Address.checksum(result.pendingTip.token_address),
Address.checksum(workspace?.default_token_address ?? Tempo.addressLookup.pathUsd),
Address.checksum(
workspace?.default_token_address ?? Tempo.getDefaultTokenAddress(result.pendingTip.chain_id),
),
)
? formatCurrencyAmount(formatAmount(result.pendingTip.amount), tokenMetadata.currency)
: formatTipAmount(
Expand Down Expand Up @@ -7320,7 +7343,8 @@ async function configCard(
options?: { canEdit?: boolean; updated?: boolean },
) {
const reactionTipConfigs = await getReactionTipConfigs(db, workspace.id)
const tokenAddress = workspace.default_token_address ?? Tempo.addressLookup.pathUsd
const tokenAddress =
workspace.default_token_address ?? Tempo.getDefaultTokenAddress(workspace.chain_id)
const token = Tempo.getTokenMetadataFallback(tokenAddress)
const networkLabel = workspace.chain_id === Tempo.chainLookup.mainnet ? 'Mainnet' : 'Testnet'
return {
Expand Down Expand Up @@ -7429,7 +7453,8 @@ function configFallbackText(
reactionTipConfigs: ReactionTipConfig[],
options?: { updated?: boolean },
) {
const tokenAddress = workspace.default_token_address ?? Tempo.addressLookup.pathUsd
const tokenAddress =
workspace.default_token_address ?? Tempo.getDefaultTokenAddress(workspace.chain_id)
return `Setting Value\nNetwork ${configNetworkLabel(workspace)}\nDefault token ${configToken(workspace).symbol} ${Tempo.explorerLink(workspace.chain_id, tokenAddress)}\nDefault amount ${formatAmount(workspace.default_amount)}\nReaction tips ${reactionTipConfigsText(reactionTipConfigs)}${options?.updated ? '\nWorkspace settings updated' : ''}`
}

Expand All @@ -7439,7 +7464,7 @@ function configNetworkLabel(workspace: DB_gen.Selectable.workspace) {

function configToken(workspace: DB_gen.Selectable.workspace) {
return Tempo.getTokenMetadataFallback(
workspace.default_token_address ?? Tempo.addressLookup.pathUsd,
workspace.default_token_address ?? Tempo.getDefaultTokenAddress(workspace.chain_id),
)
}

Expand Down
14 changes: 10 additions & 4 deletions src/chat.workers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3463,7 +3463,9 @@ test('@Tipbot mention connect link completion connects local workspace account',
accessKeyAddress: link.access_key_address,
chainId: link.chain_id,
expiresAt: link.access_key_expires_at,
tokenAddress: Address.checksum(link.default_token_address ?? Tempo.addressLookup.pathUsd),
tokenAddress: Address.checksum(
link.default_token_address ?? Tempo.getDefaultTokenAddress(link.chain_id),
),
})

const completeResponse = await client.api.account.link[':token'].$post({
Expand Down Expand Up @@ -3716,7 +3718,9 @@ test('@Tipbot mention connect link completion notifies Slack Connect external ac
accessKeyAddress: link.access_key_address,
chainId: link.chain_id,
expiresAt: link.access_key_expires_at,
tokenAddress: Address.checksum(link.default_token_address ?? Tempo.addressLookup.pathUsd),
tokenAddress: Address.checksum(
link.default_token_address ?? Tempo.getDefaultTokenAddress(link.chain_id),
),
})

const completeResponse = await client.api.account.link[':token'].$post({
Expand Down Expand Up @@ -4527,7 +4531,9 @@ test('@Tipbot mention claims Slack Connect pending tip when recipient connects',
accessKeyAddress: link.access_key_address,
chainId: link.chain_id,
expiresAt: link.access_key_expires_at,
tokenAddress: Address.checksum(link.default_token_address ?? Tempo.addressLookup.pathUsd),
tokenAddress: Address.checksum(
link.default_token_address ?? Tempo.getDefaultTokenAddress(link.chain_id),
),
}),
},
param: { token },
Expand Down Expand Up @@ -7362,7 +7368,7 @@ describe('/tip config', () => {
},
{ timeout: 10_000 }, // 10 seconds
)
.toEqual(['pathUSD', 'USDC.e', 'USDT0'])
.toEqual(['OUSD', 'pathUSD', 'USDC.e', 'USDT0'])
fetchSpy.mockRestore()
}, 20_000) // 20 seconds

Expand Down
1 change: 1 addition & 0 deletions src/lib/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ async function buildHomeView(input: {
(async () => {
// Fetch balances for every token allowed in this workspace, falling back to RPC.
const tokens = [
{ address: Tempo.addressLookup.ousd, label: 'OUSD' },
{ address: Tempo.addressLookup.pathUsd, label: 'PathUSD' },
{ address: Tempo.addressLookup.usdcE, label: 'USDC.e' },
{ address: Tempo.addressLookup.usdt0, label: 'USDT0' },
Expand Down
Loading
Loading