Skip to content

Commit

Permalink
Treasury param (#218)
Browse files Browse the repository at this point in the history
* add treasury param; update demo app & README

* changeset

* Update AbstraxionAuth.ts

Signed-off-by: Justin <[email protected]>

* update demo treasury instance

---------

Signed-off-by: Justin <[email protected]>
Co-authored-by: Justin <[email protected]>
  • Loading branch information
BurntVal and justinbarry authored Oct 1, 2024
1 parent 37cd8c3 commit 1e3bd4e
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 93 deletions.
7 changes: 7 additions & 0 deletions .changeset/slow-kangaroos-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@burnt-labs/abstraxion-core": minor
"@burnt-labs/abstraxion": minor
"demo-app": minor
---

Introduce treasury contract parameter. Look into the Abstraxion/README or the demo-app/layout for more information
48 changes: 29 additions & 19 deletions apps/demo-app/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,34 @@ const inter = Inter({ subsets: ["latin"] });
const seatContractAddress =
"xion1z70cvc08qv5764zeg3dykcyymj5z6nu4sqr7x8vl4zjef2gyp69s9mmdka";

const legacyConfig = {
contracts: [
// Usually, you would have a list of different contracts here
seatContractAddress,
{
address: seatContractAddress,
amounts: [{ denom: "uxion", amount: "1000000" }],
},
],
stake: true,
bank: [
{
denom: "uxion",
amount: "1000000",
},
],
// Optional params to activate mainnet config
// rpcUrl: "https://rpc.xion-mainnet-1.burnt.com:443",
// restUrl: "https://api.xion-mainnet-1.burnt.com:443",
};

const treasuryConfig = {
treasury: "xion17ah4x9te3sttpy2vj5x6hv4xvc0td526nu0msf7mt3kydqj4qs2s9jhe90", // Example XION treasury contract
// Optional params to activate mainnet config
// rpcUrl: "https://rpc.xion-mainnet-1.burnt.com:443",
// restUrl: "https://api.xion-mainnet-1.burnt.com:443",
};

export default function RootLayout({
children,
}: {
Expand All @@ -18,25 +46,7 @@ export default function RootLayout({
return (
<html lang="en">
<body className={inter.className}>
<AbstraxionProvider
config={{
contracts: [
// Usually, you would have a list of different contracts here
seatContractAddress,
{
address: seatContractAddress,
amounts: [{ denom: "uxion", amount: "1000000" }],
},
],
stake: true,
bank: [
{
denom: "uxion",
amount: "1000000",
},
],
}}
>
<AbstraxionProvider config={treasuryConfig}>
{children}
</AbstraxionProvider>
</body>
Expand Down
11 changes: 9 additions & 2 deletions packages/abstraxion-core/src/AbstraxionAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class AbstraxionAuth {
stake?: boolean;
bank?: SpendLimit[];
callbackUrl?: string;
treasury?: string;

// Signer
private client?: GranteeSignerClient;
Expand All @@ -38,6 +39,7 @@ export class AbstraxionAuth {
* @param {boolean} [stake] - Indicates whether staking is enabled.
* @param {SpendLimit[]} [bank] - The spend limits for the user.
* @param {string} callbackUrl - preferred callback url to override default
* @param {string} treasury - treasury contract instance address
*/
configureAbstraxionInstance(
rpc: string,
Expand All @@ -46,13 +48,15 @@ export class AbstraxionAuth {
stake?: boolean,
bank?: SpendLimit[],
callbackUrl?: string,
treasury?: string,
) {
this.rpcUrl = rpc;
this.restUrl = restUrl;
this.grantContracts = grantContracts;
this.stake = stake;
this.bank = bank;
this.callbackUrl = callbackUrl;
this.treasury = treasury;
}

/**
Expand Down Expand Up @@ -242,6 +246,10 @@ export class AbstraxionAuth {
const currentUrl = this.callbackUrl || window.location.href;
const urlParams = new URLSearchParams();

if (this.treasury) {
urlParams.set("treasury", this.treasury);
}

if (this.bank) {
urlParams.set("bank", JSON.stringify(this.bank));
}
Expand All @@ -250,12 +258,11 @@ export class AbstraxionAuth {
urlParams.set("stake", "true");
}

urlParams.set("grantee", userAddress);

if (this.grantContracts) {
urlParams.set("contracts", JSON.stringify(this.grantContracts));
}

urlParams.set("grantee", userAddress);
urlParams.set("redirect_uri", currentUrl);

const queryString = urlParams.toString(); // Convert URLSearchParams to string
Expand Down
102 changes: 31 additions & 71 deletions packages/abstraxion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ npm i @burnt-labs/abstraxion

Find an implementation demo here: [abstraxion demo](../../apps/demo-app)

First, wrap your app in the `AbstraxionProvider` at the top level
First, wrap your app in the `AbstraxionProvider` at the top level with the appropriate config

```
"use client";
Expand All @@ -29,55 +29,35 @@ const inter = Inter({ subsets: ["latin"] });
const seatContractAddress =
"xion1z70cvc08qv5764zeg3dykcyymj5z6nu4sqr7x8vl4zjef2gyp69s9mmdka";
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}): JSX.Element {
return (
<html lang="en">
<body className={inter.className}>
<AbstraxionProvider
config={{
contracts: [
// Usually, you would have a list of different contracts here
seatContractAddress,
{
address: seatContractAddress,
amounts: [{ denom: "uxion", amount: "1000000" }],
},
],
stake: true,
bank: [
{
denom: "uxion",
amount: "1000000",
},
],
}}
>
{children}
</AbstraxionProvider>
</body>
</html>
);
}
```

to activate Mainnet just add rpcUrl and restUrl endpoints to the config:

```
"use client";
import "./globals.css";
import { Inter } from "next/font/google";
import { AbstraxionProvider } from "@burnt-labs/abstraxion";
import "@burnt-labs/abstraxion/dist/index.css";
const inter = Inter({ subsets: ["latin"] });
// Example XION seat contract
const seatContractAddress =
"xion1z70cvc08qv5764zeg3dykcyymj5z6nu4sqr7x8vl4zjef2gyp69s9mmdka";
// Legacy config with individual params for stake, bank and contracts
const legacyConfig = {
contracts: [
// Usually, you would have a list of different contracts here
seatContractAddress,
{
address: seatContractAddress,
amounts: [{ denom: "uxion", amount: "1000000" }],
},
],
stake: true,
bank: [
{
denom: "uxion",
amount: "1000000",
},
],
// Optional params to activate mainnet config
// rpcUrl: "https://rpc.xion-mainnet-1.burnt.com:443",
// restUrl: "https://api.xion-mainnet-1.burnt.com:443",
};
// New treasury contract config
const treasuryConfig = {
treasury: "xion17ah4x9te3sttpy2vj5x6hv4xvc0td526nu0msf7mt3kydqj4qs2s9jhe90", // Example XION treasury contract
// Optional params to activate mainnet config
// rpcUrl: "https://rpc.xion-mainnet-1.burnt.com:443",
// restUrl: "https://api.xion-mainnet-1.burnt.com:443",
};
export default function RootLayout({
children,
Expand All @@ -87,27 +67,7 @@ export default function RootLayout({
return (
<html lang="en">
<body className={inter.className}>
<AbstraxionProvider
config={{
contracts: [
// Usually, you would have a list of different contracts here
seatContractAddress,
{
address: seatContractAddress,
amounts: [{ denom: "uxion", amount: "1000000" }],
},
],
stake: true,
bank: [
{
denom: "uxion",
amount: "1000000",
},
],
rpcUrl: "https://rpc.xion-mainnet-1.burnt.com:443",
restUrl: "https://api.xion-mainnet-1.burnt.com:443",
}}
>
<AbstraxionProvider config={treasuryConfig}>
{children}
</AbstraxionProvider>
</body>
Expand Down
2 changes: 2 additions & 0 deletions packages/abstraxion/src/components/Abstraxion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface AbstraxionConfig {
stake?: boolean;
bank?: SpendLimit[];
callbackUrl?: string;
treasury?: string;
}

export function AbstraxionProvider({
Expand All @@ -83,6 +84,7 @@ export function AbstraxionProvider({
stake={config.stake}
bank={config.bank}
callbackUrl={config.callbackUrl}
treasury={config.treasury}
>
{children}
</AbstraxionContextProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface AbstraxionContextProps {
restUrl: string;
stake?: boolean;
bank?: SpendLimit[];
treasury?: string;
logout: () => void;
}

Expand All @@ -48,6 +49,7 @@ export function AbstraxionContextProvider({
stake = false,
bank,
callbackUrl,
treasury,
}: {
children: ReactNode;
contracts?: ContractGrantDescription[];
Expand All @@ -57,6 +59,7 @@ export function AbstraxionContextProvider({
stake?: boolean;
bank?: SpendLimit[];
callbackUrl?: string;
treasury?: string;
}): JSX.Element {
const [abstraxionError, setAbstraxionError] = useState("");
const [isConnected, setIsConnected] = useState(false);
Expand All @@ -77,8 +80,9 @@ export function AbstraxionContextProvider({
stake,
bank,
callbackUrl,
treasury,
);
}, [rpcUrl, restUrl, contracts, stake, bank, callbackUrl]);
}, [rpcUrl, restUrl, contracts, stake, bank, callbackUrl, treasury]);

useEffect(() => {
const searchParams = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -116,6 +120,7 @@ export function AbstraxionContextProvider({
restUrl,
stake,
bank,
treasury,
logout,
}}
>
Expand Down

0 comments on commit 1e3bd4e

Please sign in to comment.