@tokenbound/sdk
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -1,2 +0,5 @@ | ||
import { getContract as r, encodeFunctionData as d } from "viem"; | ||
var h = Object.defineProperty; | ||
var C = (a, e, t) => e in a ? h(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t; | ||
var s = (a, e, t) => (C(a, typeof e != "symbol" ? e + "" : e, t), t); | ||
import { getContract as u, encodeFunctionData as o, pad as b, getContractAddress as w, encodeAbiParameters as g, concat as T } from "viem"; | ||
const y = [ | ||
@@ -242,23 +245,59 @@ { | ||
} | ||
], u = "0x02101dfB77FDE026414827Fdc604ddAF224F0921", c = "0x2d25602551487c3f3354dd80d76d54383a243358"; | ||
async function o(t, n, e) { | ||
const a = r({ | ||
address: u, | ||
], c = "0x02101dfB77FDE026414827Fdc604ddAF224F0921", l = "0x2d25602551487c3f3354dd80d76d54383a243358"; | ||
function I(a) { | ||
const e = a.slice(2), t = new Uint8Array(e.length / 2); | ||
for (let n = 0; n < e.length; n += 2) | ||
t[n / 2] = parseInt(e.substr(n, 2), 16); | ||
return t; | ||
} | ||
async function D(a, e, t) { | ||
const n = u({ | ||
address: c, | ||
abi: y, | ||
publicClient: e | ||
}), i = await e.getChainId(); | ||
return await a.read.account([ | ||
c, | ||
publicClient: t | ||
}), i = await t.getChainId(); | ||
return await n.read.account([ | ||
l, | ||
i, | ||
t, | ||
n, | ||
a, | ||
e, | ||
0 | ||
]); | ||
} | ||
async function m(t, n, e) { | ||
const a = r({ | ||
address: u, | ||
async function x(a, e, t) { | ||
const n = o({ | ||
abi: [ | ||
{ | ||
inputs: [], | ||
name: "initialize", | ||
outputs: [], | ||
stateMutability: "nonpayable", | ||
type: "function" | ||
} | ||
], | ||
functionName: "initialize" | ||
}); | ||
return { | ||
to: c, | ||
value: BigInt(0), | ||
data: o({ | ||
abi: y, | ||
functionName: "createAccount", | ||
args: [ | ||
l, | ||
t, | ||
a, | ||
e, | ||
0, | ||
n | ||
] | ||
}) | ||
}; | ||
} | ||
async function A(a, e, t) { | ||
const n = u({ | ||
address: c, | ||
abi: y, | ||
walletClient: e | ||
}), i = await e.getChainId(), s = d({ | ||
walletClient: t | ||
}), i = await t.getChainId(), r = o({ | ||
abi: [ | ||
@@ -275,42 +314,172 @@ { | ||
}); | ||
return a.write.createAccount([ | ||
c, | ||
return n.write.createAccount([ | ||
l, | ||
i, | ||
t, | ||
n, | ||
a, | ||
e, | ||
0, | ||
s | ||
r | ||
]); | ||
} | ||
async function T(t, n, e, a) { | ||
async function v(a, e, t, n) { | ||
return { | ||
to: t, | ||
value: e, | ||
data: d({ | ||
to: a, | ||
value: t, | ||
data: o({ | ||
abi: p, | ||
functionName: "executeCall", | ||
args: [n, e, a] | ||
args: [ | ||
e, | ||
t, | ||
n | ||
] | ||
}) | ||
}; | ||
} | ||
async function b(t, n, e, a, i) { | ||
return r({ | ||
address: t, | ||
async function k(a, e, t, n, i) { | ||
return u({ | ||
address: a, | ||
abi: p, | ||
walletClient: i | ||
}).write.executeCall([ | ||
n, | ||
e, | ||
a | ||
t, | ||
n | ||
]); | ||
} | ||
function E(a, e, t) { | ||
const n = M( | ||
l, | ||
t, | ||
a, | ||
e, | ||
"0" | ||
), i = BigInt("0").toString(16), r = b(i, { size: 32 }); | ||
return w({ | ||
bytecode: n, | ||
from: c, | ||
opcode: "CREATE2", | ||
salt: r | ||
}); | ||
} | ||
function M(a, e, t, n, i) { | ||
const r = [ | ||
{ type: "uint256" }, | ||
{ type: "uint256" }, | ||
{ type: "address" }, | ||
{ type: "uint256" } | ||
], d = [i, BigInt(e), t, n], m = g(r, d), f = T([ | ||
"0x3d60ad80600a3d3981f3363d3d373d3d3d363d73", | ||
a, | ||
"0x5af43d82803e903d91602b57fd5bf3", | ||
m | ||
]); | ||
return I(f); | ||
} | ||
class R { | ||
constructor(e) { | ||
s(this, "chainId"); | ||
s(this, "isInitialized", !1); | ||
s(this, "signer"); | ||
s(this, "walletClient"); | ||
if (!e.chainId) | ||
throw new Error("chainId is required."); | ||
if (e.signer && e.walletClient) | ||
throw new Error("Only one of `signer` or `walletClient` should be provided."); | ||
this.chainId = e.chainId, e.signer ? this.signer = e.signer : e.walletClient && (this.walletClient = e.walletClient), this.isInitialized = !0; | ||
} | ||
/** | ||
* Returns the tokenbound account address for a given token contract and token ID. | ||
* @param params.tokenContract The address of the token contract. | ||
* @param params.tokenId The token ID. | ||
* @returns The tokenbound account address. | ||
*/ | ||
getAccount(e) { | ||
const { tokenContract: t, tokenId: n } = e; | ||
try { | ||
return E(t, n, this.chainId); | ||
} catch (i) { | ||
throw i; | ||
} | ||
} | ||
/** | ||
* Returns the prepared transaction to create a tokenbound account for a given token contract and token ID. | ||
* @param params.tokenContract The address of the token contract. | ||
* @param params.tokenId The token ID. | ||
* @returns The prepared transaction to create a tokenbound account. Can be sent via `sendTransaction` on an Ethers signer or viem WalletClient. | ||
*/ | ||
async prepareCreateAccount(e) { | ||
const { tokenContract: t, tokenId: n } = e; | ||
return x(t, n, this.chainId); | ||
} | ||
/** | ||
* Returns the transaction hash of the transaction that created the tokenbound account for a given token contract and token ID. | ||
* @param params.tokenContract The address of the token contract. | ||
* @param params.tokenId The token ID. | ||
* @returns a Promise that resolves to the transaction hash of the transaction that created the tokenbound account. | ||
*/ | ||
async createAccount(e) { | ||
const { tokenContract: t, tokenId: n } = e; | ||
try { | ||
if (this.signer) { | ||
console.log("--> Ethers version of createAccount", this.signer); | ||
const i = await this.prepareCreateAccount({ tokenContract: t, tokenId: n }); | ||
return await this.signer.sendTransaction(i); | ||
} else { | ||
if (this.walletClient) | ||
return A(t, n, this.walletClient); | ||
throw new Error("No wallet client or signer available."); | ||
} | ||
} catch (i) { | ||
throw i; | ||
} | ||
} | ||
/** | ||
* Returns prepared transaction to execute a call on a tokenbound account | ||
* @param params.account The tokenbound account address | ||
* @param params.to The recipient address | ||
* @param params.value The value to send, in wei | ||
* @param params.data The data to send | ||
* @returns a Promise with prepared transaction to execute a call on a tokenbound account. Can be sent via `sendTransaction` on an Ethers signer or viem WalletClient. | ||
*/ | ||
async prepareExecuteCall(e) { | ||
const { account: t, to: n, value: i, data: r } = e; | ||
return v(t, n, i, r); | ||
} | ||
/** | ||
* Returns a hash of the transaction that executed a call on a tokenbound account | ||
* @param params.account The tokenbound account address | ||
* @param params.to The recipient address | ||
* @param params.value The value to send, in wei | ||
* @param params.data The data to send | ||
* @returns a Promise with prepared transaction to execute a call on a tokenbound account. Can be sent via `sendTransaction` on an Ethers signer or viem WalletClient. | ||
*/ | ||
async executeCall(e) { | ||
const { account: t, to: n, value: i, data: r } = e; | ||
try { | ||
if (this.signer) | ||
return console.log("--> Ethers version of executeCall"), await this.signer.sendTransaction({ | ||
to: n, | ||
value: i, | ||
data: r | ||
}); | ||
if (this.walletClient) | ||
return console.log("walletClient in executeCall", this.walletClient, t), k(t, n, i, r, this.walletClient); | ||
throw new Error("No wallet client or signer available."); | ||
} catch (d) { | ||
throw d; | ||
} | ||
} | ||
} | ||
export { | ||
m as createAccount, | ||
R as TokenboundClient, | ||
E as computeAccount, | ||
A as createAccount, | ||
p as erc6551AccountAbi, | ||
c as erc6551AccountImplementationAddress, | ||
y as erc6551RegistryAbi, | ||
u as erc6551RegistryAddress, | ||
b as executeCall, | ||
o as getAccount, | ||
T as prepareExecuteCall | ||
k as executeCall, | ||
D as getAccount, | ||
M as getCreationCode, | ||
x as prepareCreateAccount, | ||
v as prepareExecuteCall | ||
}; |
{ | ||
"name": "@tokenbound/sdk", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"type": "module", | ||
@@ -8,3 +8,3 @@ "files": [ | ||
], | ||
"types": "./dist/index.d.ts", | ||
"types": "./dist/src/index.d.ts", | ||
"main": "./dist/tokenbound-sdk.umd.cjs", | ||
@@ -18,16 +18,21 @@ "module": "./dist/tokenbound-sdk.js", | ||
}, | ||
"dependencies": { | ||
"viem": "^1.0.7" | ||
}, | ||
"devDependencies": { | ||
"@vitest/coverage-c8": "^0.31.3", | ||
"viem": "^1.0.7", | ||
"typescript": "^5.0.4", | ||
"vite": "^4.2.0", | ||
"vite-plugin-dts": "^2.2.0", | ||
"vitest": "^0.31.3" | ||
}, | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"preview": "vite preview" | ||
}, | ||
"peerDependencies": { | ||
"viem": "^0.3.1" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^4.9.3", | ||
"viem": "^0.3.1", | ||
"vite": "^4.2.0", | ||
"vite-plugin-dts": "^2.2.0" | ||
"preview": "vite preview", | ||
"test": "vitest", | ||
"coverage": "vitest run --coverage", | ||
"clean": "rm -rf node_modules/" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
33072
18
707
6
4
+ Addedviem@^1.0.7
+ Added@adraffy/ens-normalize@1.10.0(transitive)
+ Added@noble/curves@1.2.0(transitive)
+ Added@noble/hashes@1.3.2(transitive)
+ Added@scure/bip32@1.3.2(transitive)
+ Added@scure/bip39@1.2.1(transitive)
+ Addedabitype@0.9.8(transitive)
+ Addedisows@1.0.3(transitive)
+ Addedviem@1.21.4(transitive)
+ Addedws@8.13.0(transitive)
- Removed@adraffy/ens-normalize@1.9.0(transitive)
- Removed@noble/curves@1.0.0(transitive)
- Removed@noble/hashes@1.3.0(transitive)
- Removed@scure/bip32@1.3.0(transitive)
- Removed@scure/bip39@1.2.0(transitive)
- Removed@wagmi/chains@1.0.0(transitive)
- Removedabitype@0.8.7(transitive)
- Removedisomorphic-ws@5.0.0(transitive)
- Removedtypescript@5.7.2(transitive)
- Removedviem@0.3.50(transitive)
- Removedws@8.12.0(transitive)