Skip to content

Commit ddd919f

Browse files
Define1010xpeluche
andauthored
wip t bill (#487)
* wip t bill * Update index.ts --------- Co-authored-by: 0xpeluche <[email protected]>
1 parent 48f09f5 commit ddd919f

File tree

1 file changed

+59
-0
lines changed
  • src/adapters/peggedAssets/openeden-tbill

1 file changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import axios from "axios";
2+
import { sumSingleBalance } from "../helper/generalUtil";
3+
import { addChainExports } from "../helper/getSupply";
4+
import { Balances, ChainContracts, PeggedIssuanceAdapter } from "../peggedAsset.type";
5+
6+
const NODE_URL = "https://xrplcluster.com";
7+
8+
// Contracts on different chains
9+
const chainContracts: ChainContracts = {
10+
ethereum: {
11+
issued: ["0xdd50c053c096cb04a3e3362e2b622529ec5f2e8a"],
12+
},
13+
arbitrum: {
14+
issued: ["0xf84d28a8d28292842dd73d1c5f99476a80b6666a"],
15+
},
16+
solana: {
17+
issued: ["4MmJVdwYN8LwvbGeCowYjSx7KoEi6BJWg8XXnW4fDDp6"],
18+
},
19+
};
20+
21+
function createPayload(account: string) {
22+
return {
23+
method: "gateway_balances",
24+
params: [{ account, ledger_index: "validated" }],
25+
};
26+
}
27+
28+
const rippleMinted = async () => {
29+
const balances: Balances = {};
30+
const tokenCurrency = "TBL";
31+
const issuerAddress = "rJNE2NNz83GJYtWVLwMvchDWEon3huWnFn";
32+
const subscriptionOperatorAddress = "rB56JZWRKvpWNeyqM3QYfZwW4fS9YEyPWM";
33+
34+
// Fetch issuer obligations
35+
const { data: issuerData } = await axios.post(NODE_URL, createPayload(issuerAddress));
36+
const issuerObligations = parseFloat(issuerData.result.obligations[tokenCurrency] ?? "0");
37+
38+
// Fetch operator balances
39+
const { data: operatorData } = await axios.post(NODE_URL, createPayload(subscriptionOperatorAddress));
40+
const operatorAssets = operatorData.result.assets[issuerAddress] || [];
41+
42+
const heldByOperator = parseFloat(
43+
operatorAssets.find((asset: any) => asset.currency === tokenCurrency)?.value ?? "0"
44+
);
45+
46+
const circulatingSupply = Math.max(0, issuerObligations - heldByOperator);
47+
sumSingleBalance(balances, "peggedUSD", circulatingSupply, "issued");
48+
return balances;
49+
};
50+
51+
// Merge everything together using addChainExports, and override ripple with custom minted logic
52+
const adapter: PeggedIssuanceAdapter = {
53+
...addChainExports(chainContracts, undefined),
54+
ripple: {
55+
minted: rippleMinted,
56+
},
57+
};
58+
59+
export default adapter;

0 commit comments

Comments
 (0)