Skip to content
Open
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
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
modules/babylonlabs-io-btc-staking-ts
modules/babylonlabs-io-btc-staking-ts
modules/realfi-partner-sdk
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ CHANGELOG.md
flake.lock

modules/babylonlabs-io-btc-staking-ts/
modules/realfi-partner-sdk/
/.nx/workspace-data
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
registry "https://registry.npmjs.org"
ignore-engines true
8 changes: 8 additions & 0 deletions modules/realfi-partner-sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
dist/
*.tsbuildinfo
.nyc_output
coverage
*.log
.env
.DS_Store
479 changes: 479 additions & 0 deletions modules/realfi-partner-sdk/CHANGELOG.md

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions modules/realfi-partner-sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# @bitgo/realfi-partner-sdk

BitGo fork of [`@realfi-co/realfi-partner-sdk`](https://github.com/realfi-co/realfi-partner-sdk) **v2.14.0**
(`latest` / `preview` dist-tag; commit `1a8d3c0605f383e1180f8405075c08e14689ac47`).

Used by Wallet Platform to build RealFi sUSDr Plutus order transactions on Cardano.
BitGoJS `sdk-coin-ada` only pledge-signs the resulting CBOR — it does not depend on this package.

`src/` is tracked; `dist/` is built locally / at publish (`yarn workspace @bitgo/realfi-partner-sdk build`).

See `UPSTREAM.md` for rebase notes. Ticket: SI-1292.
50 changes: 50 additions & 0 deletions modules/realfi-partner-sdk/UPSTREAM.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Upstream tracking

| Field | Value |
| --- | --- |
| Upstream package | `@realfi-co/realfi-partner-sdk` |
| Upstream version | `2.14.0` (`latest` / `preview` dist-tag) |
| Upstream commit | `1a8d3c0605f383e1180f8405075c08e14689ac47` |
| BitGo package | `@bitgo/realfi-partner-sdk` (`private: true` until first npm create + publish) |
| Ticket | [SI-1292](https://linear.app/bitgo/issue/SI-1292) |

CI notes:
- `engines.node` is `>=20` to match BitGoJS (upstream / `@cardano-sdk/core` want `>=22`; WP runtime is 22).
- Root `.yarnrc` sets `ignore-engines true` so Node 20 CI can install Cardano transitive deps.
- `private: true` skips `verify-npm-packages` until the package is created on npm; unset before first publish.
- `package.json` dependencies are trimmed to packages actually imported in `src/` (upstream lists extras for tests/emulator).

## Related dist-tags (at pin time)

| Tag | Version |
| --- | --- |
| latest / preview | 2.14.0 |
| mainnet | 2.13.0 |
| preprod | 2.12.3 |

## Why a fork

BitGo does not install third-party packages from GitHub Packages into Wallet Platform CI.
This module vendors a pinned RealFi SDK **source** snapshot under `@bitgo/*` (Babylon-style) for npm beta / WP consumption.

## Build

`dist/` is **not** committed (Babylon pattern). Dual emit via `tsc`:

- `dist/esm` + `dist/types` — `tsconfig.esm.json` (NodeNext)
- `dist/cjs` — `tsconfig.cjs.json` (CommonJS) + `dist/cjs/package.json` `{ "type": "commonjs" }`

```bash
yarn workspace @bitgo/realfi-partner-sdk build
# or: node modules/realfi-partner-sdk/build.mjs
```

`lerna run build` / `prepublishOnly` regenerates `dist/` before publish.

## Rebase checklist

1. `npm view @realfi-co/realfi-partner-sdk dist-tags --registry=https://npm.pkg.github.com`
2. `npm pack @realfi-co/realfi-partner-sdk@<ver> --registry=https://npm.pkg.github.com`
3. Replace `src/` + upstream `CHANGELOG.md`; refresh this file + `package.json` version/deps.
4. `yarn workspace @bitgo/realfi-partner-sdk build` and smoke: construct SDK for preprod, read vault rate, build a stake order tx.
5. PR → merge → publish `@bitgo-beta` → bump WP.
39 changes: 39 additions & 0 deletions modules/realfi-partner-sdk/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { spawnSync } from "node:child_process";
import { createRequire } from "node:module";
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const root = dirname(fileURLToPath(import.meta.url));
const require = createRequire(import.meta.url);
const tsc = require.resolve("typescript/bin/tsc");
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));

function run(cmd, args) {
const result = spawnSync(cmd, args, { cwd: root, stdio: "inherit" });
if (result.status !== 0) {
process.exit(result.status ?? 1);
}
}

rmSync(join(root, "dist"), { recursive: true, force: true });
run(process.execPath, [tsc, "-p", "tsconfig.esm.json"]);
run(process.execPath, [tsc, "-p", "tsconfig.cjs.json"]);

mkdirSync(join(root, "dist/cjs"), { recursive: true });
writeFileSync(join(root, "dist/cjs/package.json"), `${JSON.stringify({ type: "commonjs" })}\n`);

writeFileSync(
join(root, "dist/build-info.json"),
`${JSON.stringify(
{
version: pkg.version,
builtAt: new Date().toISOString(),
note: "Built from src/ via BitGo tsc dual emit — see UPSTREAM.md",
},
null,
2,
)}\n`,
);

console.log(`built @bitgo/realfi-partner-sdk@${pkg.version}`);
62 changes: 62 additions & 0 deletions modules/realfi-partner-sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "@bitgo/realfi-partner-sdk",
"version": "2.14.0",
"private": true,
"description": "BitGo fork of RealFi partner SDK for Cardano sUSDr liquid staking (Plutus order txs).",
"type": "module",
"sideEffects": false,
"license": "UNLICENSED",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
},
"./tx-builder": {
"types": "./dist/types/tx-builder/index.d.ts",
"import": "./dist/esm/tx-builder/index.js",
"require": "./dist/cjs/tx-builder/index.js"
}
},
"files": [
"dist",
"CHANGELOG.md",
"README.md",
"UPSTREAM.md"
],
"engines": {
"node": ">=20"
},
"scripts": {
"build": "node ./build.mjs",
"prepublishOnly": "npm run build",
"test": "echo 'No unit tests in fork yet'"
},
"dependencies": {
"@blaze-cardano/core": "0.8.0",
"@blaze-cardano/data": "0.6.6",
"@blaze-cardano/query": "0.5.6",
"@blaze-cardano/sdk": "0.2.47",
"@blaze-cardano/uplc": "0.4.3",
"@sundaeswap/asset": "1.0.11",
"@sundaeswap/core": "^2.13.1"
},
"repository": {
"type": "git",
"url": "https://github.com/BitGo/BitGoJS.git",
"directory": "modules/realfi-partner-sdk"
},
"publishConfig": {
"access": "public"
},
"keywords": [
"cardano",
"realfi",
"susdr",
"staking"
],
"author": "BitGo Inc. (fork of RealFi)"
}
1 change: 1 addition & 0 deletions modules/realfi-partner-sdk/src/admin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./settings/index.js";
3 changes: 3 additions & 0 deletions modules/realfi-partner-sdk/src/admin/settings/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./types.js";
export * from "./utils.js";
export * from "./protocol-settings.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Version-neutral public entrypoint for the protocol settings admin SDK.
// The current implementation targets the v1.1-era settings shape internally.
export * from "./v1_1_rc1.js";
145 changes: 145 additions & 0 deletions modules/realfi-partner-sdk/src/admin/settings/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import type { Provider } from "@blaze-cardano/query";
import type { Blaze, Core, TxBuilder, Wallet } from "@blaze-cardano/sdk";

import type {
GovernanceConfig,
MultisigScript,
Permissions,
ProtocolConfig,
RegistryV1,
SettingsV1,
Tuple_VerificationKey_COSESign1,
} from "../../generated-types/v1_1_rc1/index.js";

/**
* COSE (CIP-8) signatures authorizing a settings change — `(VerificationKey,
* COSESign1)` tuples over the auth-payload hash from `getSettingsAuthPayloadHash`.
* Collected out-of-band (e.g. from hardware wallets), then passed to the build
* method — mirroring the orchestrator's `buildExecuteOrdersTx({ signatures })`.
*/
export type TSettingsSignatures = Tuple_VerificationKey_COSESign1[];

export interface IProtocolSettingsAdminParams {
proxyPolicyId: Core.PolicyId;
governanceConfig: GovernanceConfig;
enableTrace?: boolean;
referenceInputs?: {
settingsRefInput?: Core.TransactionUnspentOutput;
};
}

export interface IProtocolSettingsAdminSource<
P extends Provider,
W extends Wallet,
> {
readonly blaze: Blaze<P, W>;
readonly oneShotPolicyId: Core.PolicyId;
readonly enableTrace: boolean;
}

export interface IProtocolSettingsState {
proxyUtxo: Core.TransactionUnspentOutput;
proxyDatum: Core.PlutusData;
proxyAddress: Core.Address;
logicHash: Core.ScriptHash;
settingsData: Core.PlutusData;
liveSettings?: SettingsV1;
paymentCredentialHash: string;
isFrozen: boolean;
isGovernedByThisValidator: boolean;
}

export interface IBuildChangePermissionsTxParams {
nextPermissions: Permissions;
signatures: TSettingsSignatures;
}

export interface IBuildChangeConfigTxParams {
nextConfig: ProtocolConfig;
signatures: TSettingsSignatures;
}

export interface IBuildChangeLogicTxParams {
nextLogicHash?: Core.ScriptHash;
nextRegistry?: RegistryV1;
signatures: TSettingsSignatures;
}

/**
* A settings change resolved against the current on-chain state — the shared
* intermediate used to both compute the auth-payload hash and build the tx, so
* the signed message and the submitted tx always agree.
*/
export interface IResolvedSettingsChange {
redeemer:
| "ChangeLogic"
| "ChangePermissions"
| "ChangeConfig"
| "Shutdown"
| "Restore"
| "Migrate";
nextLogicHash: Core.ScriptHash;
nextSettingsData: Core.PlutusData;
receiverAddress: Core.Address;
coValidateWith?: {
rewardAccount: Core.RewardAccount;
applyWitness(tx: TxBuilder): Promise<void>;
};
}

export interface IBuildMigrateTxParams<P extends Provider, W extends Wallet> {
destination: IProtocolSettingsAdminInstance<P, W>;
/** COSE signatures satisfying this (source) validator's `migrate` permission. */
signatures: TSettingsSignatures;
/** COSE signatures satisfying the destination validator's `migrate` permission. */
destinationSignatures: TSettingsSignatures;
}

/**
* The change to authorize, passed to both `getSettingsAuthPayloadHash` (to get
* the hash to sign) and the matching build method — mirroring how the
* orchestrator passes the same order inputs to `getSignedPayloadFromOrderInputs`
* and `buildExecuteOrdersTx`.
*/
export type TSettingsChange<P extends Provider, W extends Wallet> =
| { type: "ChangePermissions"; nextPermissions: Permissions }
| { type: "ChangeConfig"; nextConfig: ProtocolConfig }
| {
type: "ChangeLogic";
nextLogicHash?: Core.ScriptHash;
nextRegistry?: RegistryV1;
}
| { type: "Shutdown" }
| { type: "Restore" }
| { type: "Migrate"; destination: IProtocolSettingsAdminInstance<P, W> };

export interface IProtocolSettingsAdminInstance<
P extends Provider,
W extends Wallet,
> {
readonly blaze: Blaze<P, W>;
readonly proxyPolicyId: Core.PolicyId;
readonly governanceConfig: GovernanceConfig;
readonly settingsScriptHash: Core.ScriptHash;
readonly settingsValidatorAddress: Core.Address;
readonly settingsRewardAccount: Core.RewardAccount;
readonly enableTrace: boolean;

getSettingsState(): Promise<IProtocolSettingsState>;
applySettingsWitness(tx: TxBuilder): Promise<void>;
}

export type TGovernancePermissionKey =
| "logic_change"
| "permission_change"
| "config_change"
| "shutdown"
| "restore"
| "migrate";

export interface IParsedProxyDatum {
logicHash: Core.ScriptHash;
settingsData: Core.PlutusData;
}

export type TPermissionedScript = MultisigScript;
Loading
Loading